-
Notifications
You must be signed in to change notification settings - Fork 43
Chainable baseURL #22
Comments
Some potential issues of chainable baseURL: 1. SyntaxShould relative paths be prefixed with const { router } = createServer('/api');
router.base('/v1');
// OR
router.base('./v1'); P.S. The native new URL('/v1', 'http://localhost:3000/api'); // => http://localhost:3000/v1
new URL('./v1', 'http://localhost:3000/api'); // => http://localhost:3000/v1
new URL('./v1', 'http://localhost:3000/api/'); // => http://localhost:3000/api/v1 2. Possible confusionThink about the following scenario: const { router } = createServer('/api'); // => http://localhost:3000/api
router.base('http://remote.com'); // => http://remote.com |
@idiotWu Summary of some of our discussions:
// Good
const apiRouter = createServer('/api').router
const githubApiRouter = createServer('https://api.github.com').router
// Bad
const server = createServer('/api')
const apiRouter = server.router
const githubApiRouter = server.router.base('/https://api.github.com')
// Also bad
const server = createServer()
const apiRouter = server.router.base('/api')
const githubApiRouter = server.router.base('/https://api.github.com')
Feel free to point out faults if exists. |
@vincentbel Ah, we have already documented it as "prefixes": So I think this issue is more a bug fix than a breaking feature? |
@idiotWu yeah, I think we don't provide |
@vincentbel one more thing, as we've discussed, the router.base('http://a.com'); // die or show warning? |
@idiotWu I think |
and warnings are just ignored by developers. 😅 |
Currently(v1.0.x),
router.base()
will always resolve to the origin of current page. For example:However, this will be counterintuitive when we code as:
Instead of getting a path of
/api/v1
, we got/v1
:(. So I'm wondering if we should resolve the givenbaseURL
against currentbaseURL
, just like the mount-paths in express apps.CC @vincentbel
The text was updated successfully, but these errors were encountered: