Comments (8)
Some potential issues of chainable baseURL:
1. Syntax
Should relative paths be prefixed with '.'
?
const { router } = createServer('/api');
router.base('/v1');
// OR
router.base('./v1');
P.S. The native URL
accepts both relative and absolute paths (notice the trailing slash):
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 confusion
Think about the following scenario: router.base()
points to another domain:
const { router } = createServer('/api'); // => http://localhost:3000/api
router.base('http://remote.com'); // => http://remote.com
from service-mocker.
@idiotWu Summary of some of our discussions:
- Servers with different origin should use
createServer
, rather thanrouter.base
(because they are different servers,router.base
is counter-intuitive)
// 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')
- Chainable baseURL can also be used to split routes. Example: https://gist.github.com/VincentBel/6a7d35e6a2999e2aa90d065a77831bfd
Feel free to point out faults if exists.
from service-mocker.
@vincentbel so the given baseURL
should be regarded as a kind of "prefixes" for the path?
Ah, we have already documented it as "prefixes":
So I think this issue is more a bug fix than a breaking feature?
from service-mocker.
@idiotWu yeah, I think we don't provide router.base
as a way to create a new server in purpose. So I also think it is more a bug fix.
from service-mocker.
@vincentbel one more thing, as we've discussed, the router.base()
method is designed for "prefixes", or we can say relative paths only. So should we reject all absolute paths or just throw a warning?
router.base('http://a.com'); // die or show warning?
from service-mocker.
@idiotWu I think die
is better because we don't mean to support this approach.😑
from service-mocker.
and warnings are just ignored by developers. 😅
from service-mocker.
from service-mocker.
Related Issues (20)
- Integration with CRA? HOT 16
- javascript errors sometimes get swallowed when inspector is running on reload HOT 7
- ngc+AOT+webpack - compile error HOT 3
- Don't put typings as dependencies HOT 11
- Project Phoenix - roadmap of ver. 2
- Hanging in chrome after reloading
- Problems with basinc routing HOT 7
- Auto reload with webpack HOT 9
- Wildcard URL param doesn't treat well empty param HOT 4
- Add middlewares into the server HOT 19
- createClient(scriptURL).ready does not resolve at root / HOT 8
- Unhandled Promise rejection: Unable to get property 'length' of undefined or null reference ; HOT 4
- Remove hash tags (#) from URL HOT 1
- Support a catch all handler
- Serious bug with route matching with nested routes
- Docs website is broken HOT 2
- Use in browser directly
- Browserify example
- Is this project still active? HOT 1
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 service-mocker.