Skip to content

Instantly share code, notes, and snippets.

@ribeiroevandro
Last active February 3, 2020 19:02
Show Gist options
  • Save ribeiroevandro/12e4ccd5785d678cc3591738e28ff0ee to your computer and use it in GitHub Desktop.
Save ribeiroevandro/12e4ccd5785d678cc3591738e28ff0ee to your computer and use it in GitHub Desktop.
Configuring json-server to expose static files, in addition to API endpoints
{
"notifications": [
{
"id": 1,
"message": "Message",
"date": "2020-02-03T14:09:52.587Z"
},
{
"id": 2,
"message": "Message 2",
"date": "2020-02-03T14:09:52.587Z"
}
]
}
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('data.json');
const middlewares = jsonServer.defaults({ static: 'src/assets' });
const port = process.env.PORT || 3000;
server.use((req, res, next) => setTimeout(next, 500));
server.use(middlewares);
server.use(router);
server.listen(port, function() {
console.log('JSON Server is running on http://localhost:' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment