Last active
November 9, 2021 11:51
-
-
Save alpody/7001356880a3709d2a9281533cfbd3f1 to your computer and use it in GitHub Desktop.
Allow access for json-server from any origins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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"} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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