Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST & DELETE request 500 #6

Closed
nicopcat opened this issue Jul 19, 2023 · 7 comments
Closed

POST & DELETE request 500 #6

nicopcat opened this issue Jul 19, 2023 · 7 comments

Comments

@nicopcat
Copy link

Try to make post request but fail:

Error: EROFS: read-only file system, open './db.json'
at Object.openSync (node:fs:601:3)
at writeFileSync (node:fs:2249:35)
at FileSync.write (/var/task/node_modules/.pnpm/lowdb@1.0.0/node_modules/lowdb/adapters/FileSync.js:53:14)
at db.write (/var/task/node_modules/.pnpm/lowdb@1.0.0/node_modules/lowdb/lib/main.js:37:21)
at /var/task/node_modules/.pnpm/json-server@0.17.0/node_modules/json-server/lib/server/router/write.js:5:8
at Layer.handle [as handle_request] (/var/task/node_modules/.pnpm/express@4.18.1/node_modules/express/lib/router/layer.js:95:5)
at next (/var/task/node_modules/.pnpm/express@4.18.1/node_modules/express/lib/router/route.js:144:13)
at create (/var/task/node_modules/.pnpm/json-server@0.17.0/node_modules/json-server/lib/server/router/plural.js:246:5)
at Layer.handle [as handle_request] (/var/task/node_modules/.pnpm/express@4.18.1/node_modules/express/lib/router/layer.js:95:5)
at next (/var/task/node_modules/.pnpm/express@4.18.1/node_modules/express/lib/router/route.js:144:13)

@VicAv99
Copy link

VicAv99 commented Jul 20, 2023

I fixed this by adding these three lines at the top of the file /api/server.js.

const fs = require("fs")
const path = require("path")
const db = JSON.parse(fs.readFileSync(path.join("db.json")))

Then you can update router to use the db const.

const router = jsonServer.router(db)

@nicopcat
Copy link
Author

Thank you, your code is working well.

@whoafridi
Copy link

@nicopcat , @VicAv99 thanks for covering this issues on regarding server deployment. My another question, is that you guys have an experience using json-server as I know from that issue so , my mind is thinking that - - when a post, put or update req happens then the data is modified ? & then if data is modified then the db.json also updated right? is this actually works here or not? I've found many post that data is not save in db.json so data will gone when the server stop or after execution . . Can you guide me to that . . Thank you again both of you

@kitloong
Copy link
Owner

kitloong commented Oct 4, 2023

Thanks @VicAv99 , I have added your solution to the ./api/server.js as an option.

@kitloong kitloong mentioned this issue Oct 4, 2023
Closed
@whoafridi
Copy link

Thanks @VicAv99 , I have added your solution to the ./api/server.js as an option.

this is so nice - appreciate everyone.

@jikkuatwork
Copy link

I am confused! Are you guys implementing this for persisting data till the serverless function dies? The data will just get deleted after the serverless function stops. If it works like that why is it disabled/commented out? Even in the demo app, you can enable POST/DELETE without any consequence because data will get deleted!

Am I missing something?

@TinhoLima
Copy link

I was having great difficulties, so thank you very much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants