Next.js Discord

Discord Forum

Method Not Allowed

Answered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
I'm having an issue where I have created a new route.ts (with a POST method) segment in my app directory under /api/query and every thing went just fine until I deployed the app. After deploying to Vercel and when I send a request to that route it yells at me "405 Method is not allowed"
Answered by Toyger
then as I said it will not work for app itself.
static files served by cdn/file server
but api/pages/rsc/.... all is serverless and they dont have access to your data directly
server where your db file located or server which gave you this file for download can be at least in different parts of datacenter, so functions don't have physical acess to it.
you basically better take free plan of mongo or planetscale or supabase, they probably will be enough for you.
View full answer

26 Replies

Toyger
maybe you'll provide some code
Spectacled bearOP
now that I'm looking into the logs of vercel there is an error occuring in the route when it's called. but why it's showing 405 instead of 500?
the route code is:
const body: Body = await req.json();

  const data = await orm(body.sql, body.params);

  const sanitizedData = dbDataSanitizer(data, {
    booleanFields: body.booleanFields,
    jsonFields: body.jsonFields,
  });

  return NextResponse.json(body.isSingle ? sanitizedData[0] : sanitizedData);

the error in the orm function which is establishing a connection to an sqlite database
Spectacled bearOP
It's like this:
I have very small app that I don't want to bother and create a db for it (the app will not be opened by anyone but me) so I decided to add SQLite3 db and call it from and api whenever I need it and it will be synced between dev and production
the path I'm passing to call this database is good in the dev env but not in the production and actually I'm trying to find out where the hell the file is ending in the production env
Toyger
you host it on vercel?
Spectacled bearOP
yes
Toyger
I am not sure it possible, they use ephermal drives, so eventually it will delete all data, and it probably impossible to retrieve data from vercel back to repository
Spectacled bearOP
well I'm sorry for interruption but I was able to read the database file so it seems the problem with operning the database file on vercel and not reading the file itself because the path is still the same on vercel I added some logs and figured that out
no I added a route segment for test with GET method to download the database file so I can keep it in sync with the development and actually it downloaded the file without any problem
Toyger
and is this download path working right now?
Spectacled bearOP
so the file and its path is not affected by vercel at all the whole problem is with opening sqlite3 database in vercel
@Toyger and is this download path working right now?
Spectacled bearOP
yes
the download is running fine but within the post method I'm getting this:
Error: ENOENT: no such file or directory, open './database/data.db'
at Object.openSync (node:fs:603:3)
at Object.readFileSync (node:fs:471:35)
at l (/var/task/.next/server/app/(routes)/api/query/route.js:1:1497)
at h (/var/task/.next/server/app/(routes)/api/query/route.js:1:646)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:41322 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: './database/data.db'
}
Toyger
https://vercel.com/guides/is-sqlite-supported-in-vercel#local-storage-and-serverless
till your site will have small traffic theoretically it possible, but we just don't know what vercel retention policy, maybe it's 5min per instance.
Spectacled bearOP
🫠🫠🫠🫠
Toyger
so you download it by direct link?
Spectacled bearOP
yes
and it worked
but as I understand from the post
it says that I can't write to it
and that's reasonable
so blob is there on vercel but no writing will be happening
Toyger
then as I said it will not work for app itself.
static files served by cdn/file server
but api/pages/rsc/.... all is serverless and they dont have access to your data directly
server where your db file located or server which gave you this file for download can be at least in different parts of datacenter, so functions don't have physical acess to it.
you basically better take free plan of mongo or planetscale or supabase, they probably will be enough for you.
Answer
Spectacled bearOP
yup I guess that what I'm gonna do thanks I'll mark it as answer