Giter VIP home page Giter VIP logo

Comments (8)

tobymarsden avatar tobymarsden commented on August 20, 2024 1

I have a need to mount on a prefix with a dynamic segment, e.g. /users/:user/app/

I think I can hack koajs/mount to allow for a regexp prefix, but is there a better way of doing this?

from mount.

tj avatar tj commented on August 20, 2024

for vhost-style routing you can use this.subdomains or this.host

from mount.

jeromew avatar jeromew commented on August 20, 2024

I understand (found https://github.com/koajs/examples/tree/master/vhost for instance).

I am still hesitating on this and probably need to discover koajs a bit more.

basically I consider that the domain is part of the whole rewriting scheme of an application. After all, once the request is inside the server, why should we make a difference between host and pathname for routing purposes ?

it can make sense to mount a blog on either

  1. blog.domain.com/
  2. www.domain.com/blog/

but i don't see why the solution for mounting should be different. does it make sense ?

from mount.

tj avatar tj commented on August 20, 2024

for this module I'd like to just keep it simple and mount on paths, but I think if we add koajs/vhost or similar that would be great

from mount.

jeromew avatar jeromew commented on August 20, 2024

@tobymarsden you could take a look at npm's koa-router module.

from mount.

tobymarsden avatar tobymarsden commented on August 20, 2024

Thanks @jeromew -- I've been playing with it, but couldn't figure out how to mount another Koa app onto a route. Do you know if this is possible?

from mount.

jeromew avatar jeromew commented on August 20, 2024

Hello,
I am not sure this is the right place to discuss this ;-) but you can "summarize" a koa app into a single middleware by calling

var compose = require('koa-compose');
var mw = compose(app.middleware);

then you can register this with koa-router like so :

r.get('/users/:user/app/', mw)

so this could do the trick for a 'GET' based application but it would depend a lot on what you are trying to achieve i suppose and there are other options with koa-router.

You might also need to add a middleware in front of the app.middleware array if you need the rewriting scheme that koa mount offers.

I suggest you ask further questions there or on koa mailing list (google groups) since koa mount is not directed towards complex routing, or parameter based rewriting.

from mount.

tobymarsden avatar tobymarsden commented on August 20, 2024

@jeromew -- perfect, thanks! koa-compose is the missing piece I'm after, and saves me chopping koa-mount up in nasty ways, though I can still see a use-case for the mount paths supporting a regexp.

from mount.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.