Unverified Commit 53f4f82e authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Catch all requests in custom server (#8704)

Some users aren't aware they need to edit their custom server to support various HTTP Methods (e.g. POST for API Routes).

Instead, we should just handle all HTTP Methods out-of-the-box.

---

Closes #8237
parent a809368e
...@@ -21,7 +21,7 @@ app.prepare().then(() => { ...@@ -21,7 +21,7 @@ app.prepare().then(() => {
return app.render(req, res, '/posts', { id: req.params.id }) return app.render(req, res, '/posts', { id: req.params.id })
}) })
server.get('*', (req, res) => { server.all('*', (req, res) => {
return handle(req, res) return handle(req, res)
}) })
......
...@@ -29,7 +29,7 @@ fastify.register((fastify, opts, next) => { ...@@ -29,7 +29,7 @@ fastify.register((fastify, opts, next) => {
}) })
}) })
fastify.get('/*', (req, reply) => { fastify.all('/*', (req, reply) => {
return app.handleRequest(req.req, reply.res).then(() => { return app.handleRequest(req.req, reply.res).then(() => {
reply.sent = true reply.sent = true
}) })
......
...@@ -39,7 +39,7 @@ app.prepare().then(async () => { ...@@ -39,7 +39,7 @@ app.prepare().then(async () => {
}) })
server.route({ server.route({
method: 'GET', method: '*',
path: '/{p*}' /* catch all route */, path: '/{p*}' /* catch all route */,
handler: defaultHandlerWrapper(app) handler: defaultHandlerWrapper(app)
}) })
......
...@@ -21,7 +21,7 @@ app.prepare().then(() => { ...@@ -21,7 +21,7 @@ app.prepare().then(() => {
ctx.respond = false ctx.respond = false
}) })
router.get('*', async ctx => { router.all('*', async ctx => {
await handle(ctx.req, ctx.res) await handle(ctx.req, ctx.res)
ctx.respond = false ctx.respond = false
}) })
......
...@@ -13,7 +13,7 @@ app.prepare().then(() => { ...@@ -13,7 +13,7 @@ app.prepare().then(() => {
server.get('/b', (req, res) => app.render(req, res, '/b', req.query)) server.get('/b', (req, res) => app.render(req, res, '/b', req.query))
server.get('*', (req, res) => handle(req, res)) server.all('*', (req, res) => handle(req, res))
server.listen(port, err => { server.listen(port, err => {
if (err) throw err if (err) throw err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment