Hello, I have deployed an app using Digitalocean APP but every POST request is failing 405 Method not allowed while it’s working in local.
as per Nuxt 3 documentation, I have setup environment Variable as NITRO_PRESET=digital-ocean and similar.
/server/api/aut/login.post.ts
export default defineEventHandler(async (event) => {
const body = await readBody<{ email: string; password: string; rememberMe: boolean }>(event)
const config = useRuntimeConfig()
const {
email,
password,
rememberMe
} = body
const data = await $fetch(process.env.API_BASE_URL + "/api/token/", {
method: "POST",
body: body
})
if (data) {
setCookie(event, 'access', data.access, {
httpOnly: true,
path: '/',
sameSite: 'strict',
secure: process.env.NODE_ENV === 'production',
expires: rememberMe ? new Date(Date.now() + config.cookieRememberMeExpires) : new Date(Date.now() + config.cookieAccessExpires),
})
setCookie(event, 'refresh', data.refresh, {
httpOnly: true,
path: '/',
sameSite: 'strict',
secure: process.env.NODE_ENV === 'production',
expires: rememberMe ? new Date(Date.now() + config.cookieRememberMeExpires) : new Date(Date.now() + config.cookieRefreshExpires),
})
}
return data
})
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
I recently had a similar problem, make sure that you are using
https://
rather thanhttp://
when making the requests. Otherwise, if you send a POST request tohttp://
which then gets redirected tohttps://
you would most likely hit the problem that you’ve described.Let me know how it goes.
Best,
Bobby