Giter VIP home page Giter VIP logo

Comments (11)

jonathanong avatar jonathanong commented on August 20, 2024

weird. maybe something else is going on. you also have to mind the trailing /s

from mount.

clintwood avatar clintwood commented on August 20, 2024

@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.

tj avatar tj commented on August 20, 2024

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.

clintwood avatar clintwood commented on August 20, 2024

@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.

tj avatar tj commented on August 20, 2024

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.

clintwood avatar clintwood commented on August 20, 2024

Yup! I'll go with the redirect... technically it is correct... thanks!

from mount.

clintwood avatar clintwood commented on August 20, 2024

@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.

jonathanong avatar jonathanong commented on August 20, 2024

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.

clintwood avatar clintwood commented on August 20, 2024

Ya it doesn't make sense, but it feels like the / was just fabricated... anyhow it's easy to workaround!

from mount.

matthewmueller avatar matthewmueller commented on August 20, 2024

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.

clintwood avatar clintwood commented on August 20, 2024

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)

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.