Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
152 lines
3.7 KiB
JavaScript
152 lines
3.7 KiB
JavaScript
// @ts-check
|
|
|
|
if (process.env.POLYFILL_FETCH) {
|
|
// @ts-expect-error
|
|
global.fetch = require('node-fetch').default
|
|
// @ts-expect-error
|
|
global.Request = require('node-fetch').Request
|
|
// @ts-expect-error
|
|
global.Headers = require('node-fetch').Headers
|
|
}
|
|
|
|
const { readFileSync } = require('fs')
|
|
|
|
/** @type {import('next').default} */
|
|
// @ts-ignore: missing interopDefault
|
|
const next = require('next')
|
|
|
|
const { join } = require('path')
|
|
const { parse } = require('url')
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
const dir = __dirname
|
|
const port =
|
|
(process.env.PORT ? Number.parseInt(process.env.PORT) : undefined) || 3000
|
|
const { createServer } = require(
|
|
process.env.USE_HTTPS === 'true' ? 'https' : 'http'
|
|
)
|
|
|
|
const app = next({ dev, hostname: 'localhost', port, dir })
|
|
const handleNextRequests = app.getRequestHandler()
|
|
|
|
const httpOptions = {
|
|
key: readFileSync(join(__dirname, 'ssh/localhost-key.pem')),
|
|
cert: readFileSync(join(__dirname, 'ssh/localhost.pem')),
|
|
}
|
|
|
|
process.on('unhandledRejection', (err) => {
|
|
console.error('unhandledRejection:', err)
|
|
})
|
|
|
|
app.prepare().then(() => {
|
|
const server = createServer(httpOptions, async (req, res) => {
|
|
// let next.js handle assets from /_next/
|
|
if (/\/_next\//.test(req.url)) {
|
|
return handleNextRequests(req, res)
|
|
}
|
|
|
|
if (req.url === '/no-query') {
|
|
return app.render(req, res, '/no-query')
|
|
}
|
|
|
|
if (req.url === '/unhandled-rejection') {
|
|
Promise.reject(new Error('unhandled rejection'))
|
|
return res.end('ok')
|
|
}
|
|
|
|
if (/setAssetPrefix/.test(req.url)) {
|
|
app.setAssetPrefix(`http://127.0.0.1:${port}`)
|
|
} else if (/setEmptyAssetPrefix/.test(req.url)) {
|
|
app.setAssetPrefix('')
|
|
} else {
|
|
// This is to support multi-zones support in localhost
|
|
// and may be in staging deployments
|
|
app.setAssetPrefix('')
|
|
}
|
|
|
|
if (/test-index-hmr/.test(req.url)) {
|
|
return app.render(req, res, '/index')
|
|
}
|
|
|
|
if (/dashboard/.test(req.url)) {
|
|
return app.render(req, res, '/dashboard')
|
|
}
|
|
|
|
if (/static\/hello\.text/.test(req.url)) {
|
|
return app.render(req, res, '/static/hello.text')
|
|
}
|
|
|
|
if (/no-slash/.test(req.url)) {
|
|
try {
|
|
await app.render(req, res, 'dashboard')
|
|
} catch (err) {
|
|
res.end(err.message)
|
|
}
|
|
}
|
|
|
|
if (/custom-url-with-request-handler/.test(req.url)) {
|
|
return handleNextRequests(req, res, parse('/dashboard', true))
|
|
}
|
|
|
|
if (/legacy-methods\/render-to-html/.test(req.url)) {
|
|
try {
|
|
const html = await app.renderToHTML(req, res, '/dynamic-dashboard', {
|
|
q: '1',
|
|
})
|
|
res.end(html)
|
|
} catch (err) {
|
|
res.end(err.message)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (/legacy-methods\/render404/.test(req.url)) {
|
|
try {
|
|
await app.render404(req, res, parse('/__non_existent__?q=1', true))
|
|
} catch (err) {
|
|
res.end(err.message)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (/legacy-methods\/render-error/.test(req.url)) {
|
|
try {
|
|
res.statusCode = 500
|
|
await app.renderError(new Error('kaboom'), req, res, '/dashboard', {
|
|
q: '1',
|
|
})
|
|
} catch (err) {
|
|
res.end(err.message)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (/legacy-methods\/render-error-to-html/.test(req.url)) {
|
|
try {
|
|
res.statusCode = 500
|
|
const html = await app.renderErrorToHTML(
|
|
new Error('kaboom'),
|
|
req,
|
|
res,
|
|
'/dashboard',
|
|
{ q: '1' }
|
|
)
|
|
res.end(html)
|
|
} catch (err) {
|
|
res.end(err.message)
|
|
}
|
|
return
|
|
}
|
|
|
|
handleNextRequests(req, res)
|
|
})
|
|
|
|
server.listen(port, (err) => {
|
|
if (err) {
|
|
throw err
|
|
}
|
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
|
})
|
|
})
|