question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsonServer.rewriter not work in module solution

See original GitHub issue

My main code is very simple as below,

/// Set default middlewares (logger, static, cors and no-cache)
server.use(middlewares);

// To handle POST, PUT and PATCH you need to use a body-parser
// You can use the one used by JSON Server
server.use(jsonServer.bodyParser);

// Use default router
// server.use(jsonServer.rewriter({
//     '/api/v1/': '/'
// }));
server.use('/api/v1', router);
server.listen(3000, () => {
    console.log('JSON Server is running')
});

neither rewriter nor server.use('/api/v1', router) worked, the access url only happened on / not /api/v1/...

any idea?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
qiluocommented, May 15, 2017

Thanks it finally worked. Hopefully document could get improved

0reactions
rchodcommented, Jul 30, 2019

@qiluo Hello, maybe you can close this issue ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsonserver not redirecting using rewriter - Stack Overflow
If i start the server using "node server" then it starts the json server and also supports rewriting. However if use npx json-server...
Read more >
typicode/json-server - Gitter
i.e. I'm trying to do something like below in routes.js but only for a GET request on an endpoint, let's say GET /clients...
Read more >
json-server | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
3 ways to mock an API in JavaScript | Where those can help you
So, my suggestion is creating a structure and use json-server as module and not as command line directly. Copy. # node ApiMock/server OR...
Read more >
How to use the json-server.defaults function in json-server | Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found