Closed maximilian-schwarz closed 2 years ago
I found the issue. Now the solution for all others. It was a miss configuration in the server middleware.
import express from 'express'
import bodyParser from 'body-parser'
const app = express()
app.use(bodyParser.json())
app.post('/api/hello', function(req, res) {
const { info } = req.body
console.log(info)
res
.status(200)
.json({ info })
.end()
})
export default app
IT'S VERY IMPORTANT TO USE THE FULL PATH. IF NOT THE SERVERMIDDLWARE IS NOT WORKING!!!
I used in my server middleware only:
app.post('/hello');
instead of:
app.post('/api/hello')
Hello,
I am currently trying to deploy my NuxtJS app on Vercel. Everything is working fine, except for my server middleware. Currently I have created a server middleware as a test, which simply returns the entered parameters as JSON.
Current behaviour local
Locally, I start the application with 'npm run dev'. Everything is accessible under localhost:3000.
I call the following endpoint: http://localhost:3000/api/mailchimp/test
I get a correct JSON response with the content type: application/json.
Current behaviour vercel
If I now deploy the application to vercel and then call the endpoint, I have the problem that I do not receive a JSON response, but simply the _.vue page is loaded.
Folder structure:
api/mailchimp/test.js:
vercel.json
middleware/page.js
nuxt.config.js:
I try a lot of different things but nothing is working. On localhost everything is working fine. Only at vercel the Endpoints not working :(. Does anyone have any idea what I'm doing wrong? Thanks for you help.