typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.93k stars 7.02k forks source link

serve static data #159

Open gimm opened 9 years ago

gimm commented 9 years ago

I had this in db.json

{
    'login': {
    'username': 'xxx',
    'age': 12
    }
}

I want /login always return this object to me, it should not be updated by POST request. How can I do this? Thanks in advance.

typicode commented 9 years ago

Hi @gimm

You need to use the project as a module if you want to block some routes:

var jsonServer = require('json-server')
var server = jsonServer.create()

server.use(jsonServer.defaults)

server.post('login', function (req, res) {
  res.sendStatus(404)
})

server.use(jsonServer.router('db.json'))

server.listen(3000)

But personally, if it's for a fake server that you use locally, I wouldn't worry much about that.