By Sam
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!
Accepted Answer
Hi there,
I recently had a similar problem, make sure that you are using https://
rather than http://
when making the requests. Otherwise, if you send a POST request to http://
which then gets redirected to https://
you would most likely hit the problem that you’ve described.
Let me know how it goes.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.