nuxt / create-nuxt-app

Create Nuxt.js App in seconds.
MIT License
3.48k stars 430 forks source link

When using Koa alongside Nuxt, ability to use different `router.base` from root, and that Koa follows suit #82

Open renoirb opened 6 years ago

renoirb commented 6 years ago

What problem does this feature solve?

Have Koa function alongside Nuxt, when Nuxt has a different context-root than / (e.g. have /foo/, instead of /, as in http://example.org/foo/).

Nuxt supports to tell which context-root (e.g. instead of //foo/) to use when running with nuxt.config.js's router.base option. (see nuxt.js/.../configuration-router)

// nuxt.config.js
module.exports = {
  router: {
    base: '/foo/'
  }
}

But when using Koa alongside Nuxt, Koa throws exceptions.

This might just be a matter of having the right combination of settings, initialized in the right order. But which settings, and where is the question

P.S. This is an issue created by the request of @clarkdo, following up nuxt/koa-template - Document how to also make Koa match Nuxt's router.base #c29

What does the proposed changes look like?

  1. Some setting that says what is the baseUri to use, defaults to / as usual
  2. Both Nuxt and Koa takes the configuration into account
  3. Should work in any deployment mode: dev, compiled, etc.

P.S.: I've started working towards this while refactoring clarkdo/hare (see renoirb/experiments-nuxt-koa-env-runtime-201806, branch rework-hare-20180619 as a starting point)

This feature request is available on Nuxt community (#c58)
renoirb commented 6 years ago

FYI: I had something that works. I should make a repository and/or PR soon(ish) and add a link here.