Comments (11)
weird. maybe something else is going on. you also have to mind the trailing /
s
from mount.
@jonathanong, thanks... the trailing /
hint exposed the issue... in the browser
http://domain.com/website
!== http://domain.com/website/
duh! yet koa-mount
served the root view in both cases (is that the desired behavior?). The browser did not correctly base relative URLs for the former request, whereas, for the latter it did.
To resolve this and prevent the former path being served, the mount(...)
path must be specified as /website/
with a trailing /
. I.e.:
app.use(mount('/website/', webapp));
from mount.
although they're different urls most web apps/frameworks treat them as the same, or redirect since it can be bad for SEO, as far as base
goes I'm not sure I haven't used it
from mount.
@visionmedia what I thought was the fix above, causes a not found
for <a href="home">
in page served by http://domain.com/website/
as seen here:
app.use(mount('/website/', webapp)); // with trailing '/'
// breaks `<a href="home">` --> koa-mount enter /website/about -> about +1ms
// but
app.use(mount('/website', webapp)); // without trailing /
// works `<a href="home">` --> koa-mount enter /website/about -> /about +1ms
A redirect here for this feels weird... I'm trying really hard to avoid a base
tag... which would be even weirder...
from mount.
ah yea that's annoying with relative hrefs. /website/ is technically the correct thing there if you can't build the absolute pathname of /website/about using the .mountPath, so redirects would probably be the only other option there really
from mount.
Yup! I'll go with the redirect... technically it is correct... thanks!
from mount.
@visionmedia, damn... is this really correct?
For mount('/website', app)
with a request url http://domain.com/website
,
should the app really have a this.path == '/'
? Should it rather be this.path == ''
? and only for url http://domain.com/website/
it should be this.path == '/'
?
from mount.
this.path === ''
doesn't make sense though. i think this is more of a documentation issue. maybe include a middleware to redirect to trailing slashes or something.
from mount.
Ya it doesn't make sense, but it feels like the /
was just fabricated... anyhow it's easy to workaround!
from mount.
Just ran into this. Kinda sucks cause it ruins the abstract a little bit, you'd expect this.redirect('/')
to be relative to the mounted app path, but can't think of a good way of handling this outside of monkey-patching redirect within mount.
from mount.
I ended up doing this in koa app module that could potentially be mounted:
var app = koa();
...
app.use(function* redirect(next) {
// redirect if prefix is not terminated with '/'
if (this.originalUrl == this.mountPath && this.mountPath.slice(-1) != '/') {
debug('redirect: %s -> %s/', this.mountPath, this.mountPath);
this.status = 301;
this.redirect(this.mountPath + '/');
}
// next
yield* next;
});
Not sure this is entirely the right way to go...
from mount.
Related Issues (20)
- next branch?? HOT 10
- koa-mount + koa2 + koa-convert + koa-router HOT 17
- Doesn't work with Koa 2.0 HOT 3
- Should redirects be absolute? HOT 3
- Needs to be updated for latest koa-router? HOT 7
- Compatibility with koa@2.* HOT 1
- del
- Release 2.0 version HOT 1
- koa-mount v3
- Use of async function causes problems in recent versions (but not latest) of node.js HOT 4
- [Question] Nested mounting and ctx.mountPrefix HOT 4
- Notes on updating from koa v1.x to 2.x using koa-convert HOT 1
- Is there any way to access the routes this creates? HOT 2
- Path unmounted if error occurs HOT 2
- mounted app.context doesn't get applied to parent app HOT 4
- Missing trailing slash and relative paths HOT 1
- Cannot read property 'middleware' of undefined HOT 3
- Custom error thrown inside mounted app is converted to native Error HOT 2
- remove mounted app support
- Protected path with auth 🚧 -- Question HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mount.