-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
madhuredra
committed
Jan 16, 2024
1 parent
03953eb
commit 5431ef8
Showing
5 changed files
with
30 additions
and
51 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
// See https://github.com/typicode/json-server#module | ||
const jsonServer = require('json-server') | ||
const cors = require('cors') | ||
const path = require('path') | ||
|
||
const server = jsonServer.create() | ||
const router = jsonServer.router(path.join(__dirname, 'db.json')) | ||
|
||
// Uncomment to allow write operations | ||
// const fs = require('fs') | ||
// const path = require('path') | ||
// const filePath = path.join('db.json') | ||
// const data = fs.readFileSync(filePath, "utf-8"); | ||
// const db = JSON.parse(data); | ||
// const router = jsonServer.router(db) | ||
|
||
// Comment out to allow write operations | ||
const router = jsonServer.router('db.json') | ||
|
||
const middlewares = jsonServer.defaults() | ||
|
||
server.use(cors()) | ||
server.use(jsonServer.bodyParser) | ||
server.use(middlewares) | ||
// Add this before server.use(router) | ||
server.use(jsonServer.rewriter({ | ||
'/api/*': '/$1', | ||
'/blog/:resource/:id/show': '/:resource/:id' | ||
})) | ||
server.use(router) | ||
server.listen(3000, () => { | ||
console.log('JSON Server is running') | ||
}) | ||
|
||
const PORT = 8000 | ||
|
||
server.listen(PORT, () => { | ||
console.log(`JSON Server is running on http://localhost:${PORT}`) | ||
}) | ||
// Export the Server API | ||
module.exports = server |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
"destination": "api/server.js" | ||
} | ||
] | ||
} | ||
} |