90e97b535b
## Why Some users prefer to use a custom server implementation that handles body parsing. If they do this, they have no way to opt out of all body parsing in API Routes. Requests with bodies die if next's `bodyParser` is not disabled. Requests just hang forever. Instead of adding [this config](https://nextjs.org/docs/api-routes/api-middlewares#custom-config) to every API Route, we do a simple check to avoid parsing the body twice. Fixes #8315 Fixes #7960
28 lines
612 B
JavaScript
28 lines
612 B
JavaScript
const next = require('next')
|
|
const bodyParser = require('body-parser')
|
|
const express = require('express')
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
const dir = __dirname
|
|
const port = process.env.PORT || 3000
|
|
|
|
const app = next({ dev, dir })
|
|
const handleNextRequests = app.getRequestHandler()
|
|
|
|
app.prepare().then(() => {
|
|
const server = express()
|
|
|
|
server.use(bodyParser.json({ limit: '5mb' }))
|
|
|
|
server.all('*', (req, res) => {
|
|
handleNextRequests(req, res)
|
|
})
|
|
|
|
server.listen(port, (err) => {
|
|
if (err) {
|
|
throw err
|
|
}
|
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
|
})
|
|
})
|