Node.js and express : Routes

你。 提交于 2019-12-02 05:53:40

This route router.get('/inscription', ...) in your inscription router is configured for the route /inscription/inscription which is likely not what you intended. This is because you've specified it in two places:

app.use('/inscription', inscription);
router.get('/inscription', ...)

So, the whole router is on /inscription from the app.use('/inscription', inscription). That means that any route the router itself defines will be added to that path.

It isn't exactly clear from your question exactly what you intend for the URLs to be. But, if you just want the above router.get() to work for a /inscription URL, then change:

router.get('/inscription', ...)

to:

router.get('/', ...)

When you use app.use('/inscription', inscription);, every single route in that router will be prefixed with /inscription. So, this route:

router.post('/adduser', ...)

will be mounted at:

/inscription/adduser

Or, if you want all the inscription routes to be at the top level too, then change:

app.use('/inscription', inscription);

to this:

app.use('/', inscription);

So that nothing is added to the path beyond what the router itself defines.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!