Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preview Mode Should Not Cache (#10636)
* Preview Mode Should Not Cache * add import * fix import * add tests * Add real serverless mode tests
- Loading branch information
Showing
4 changed files
with
131 additions
and
13 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,41 @@ | ||
const http = require('http') | ||
const url = require('url') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const server = http.createServer((req, res) => { | ||
let { pathname } = url.parse(req.url) | ||
if (pathname.startsWith('/_next/data')) { | ||
pathname = pathname | ||
.replace(`/_next/data/${process.env.BUILD_ID}/`, '/') | ||
.replace(/\.json$/, '') | ||
} | ||
console.log('serving', pathname) | ||
|
||
if (pathname === '/favicon.ico') { | ||
res.statusCode = 404 | ||
return res.end() | ||
} | ||
|
||
if (pathname.startsWith('/_next/static/')) { | ||
res.write( | ||
fs.readFileSync( | ||
path.join( | ||
__dirname, | ||
'./.next/static/', | ||
pathname.slice('/_next/static/'.length) | ||
), | ||
'utf8' | ||
) | ||
) | ||
return res.end() | ||
} else { | ||
const re = require(`./.next/serverless/pages${pathname}`) | ||
return typeof re.render === 'function' | ||
? re.render(req, res) | ||
: re.default(req, res) | ||
} | ||
}) | ||
|
||
server.listen(process.env.PORT, () => { | ||
console.log('ready on', process.env.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