Skip to content

Instantly share code, notes, and snippets.

@alpody
Last active November 9, 2021 11:51
Show Gist options
  • Save alpody/7001356880a3709d2a9281533cfbd3f1 to your computer and use it in GitHub Desktop.
Save alpody/7001356880a3709d2a9281533cfbd3f1 to your computer and use it in GitHub Desktop.
Allow access for json-server from any origins
module.exports = (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Method','GET HEAD PUT PATCH POST DELETE')
res.header('Access-Control-Allow-Headers', 'Origin,Content-Type,Accept,Authorization')
res.header('Vary', 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers')
next()
}
{
"users":[
{"id":1, "login":"user1", "email":"user1@example.com"},
{"id":2, "login":"user2", "email":"user2@example.com"},
{"id":3, "login":"user3", "email":"user3@example.com"}
]
}
#!/bin/sh
json-server -H 192.168.56.103 --nc --middlewares cors.js -w db.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment