Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure rewrites are handled in serverless mode correctly (#10697)
Co-authored-by: Joe Haddad <timer150@gmail.com>
- Loading branch information
Showing
5 changed files
with
132 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default async (req, res) => res.json({ query: req.query }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const path = require('path') | ||
const http = require('http') | ||
|
||
const server = http.createServer((req, res) => { | ||
const pagePath = page => path.join('.next/serverless/pages/', page) | ||
const render = page => { | ||
require(`./${pagePath(page)}`).render(req, res) | ||
} | ||
const apiCall = page => { | ||
require(`./${pagePath(page)}`).default(req, res) | ||
} | ||
|
||
switch (req.url) { | ||
case '/blog/post-1': { | ||
return render('/blog/[post]') | ||
} | ||
case '/query-rewrite/first/second': { | ||
return render('/with-params') | ||
} | ||
case '/api-hello-param/first': { | ||
return apiCall('/api/hello') | ||
} | ||
case '/api-dynamic-param/first': { | ||
return apiCall('/api/dynamic/[slug]') | ||
} | ||
default: { | ||
res.statusCode(404) | ||
return res.end('404') | ||
} | ||
} | ||
}) | ||
|
||
const port = process.env.PORT || 3000 | ||
server.listen(port, () => { | ||
console.log('ready on', port) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters