Unverified Commit e01f0e4c authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove leftover server.js files in test suite (#45408)

Removes leftover files that were used for `target: 'serverless'` which has been removed in Next.js 13.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent a47841b0
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)
})
const path = require('path')
const http = require('http')
const url = require('url')
const server = http.createServer((req, res) => {
const render = async (page) => {
const mod = require(`./${path.join('.next/serverless/pages/', page)}`)
try {
return await (mod.render || mod.default || mod)(req, res)
} catch (err) {
res.statusCode = 500
return res.end('internal error')
}
}
const { pathname } = url.parse(req.url)
switch (pathname) {
case '/about':
return render('/about.js')
case '/api/post':
case '/api/post/hello':
case '/api/post/hello/world': {
return render('/api/post/[[...slug]].js')
}
case '/nested':
case '/nested/hello':
case '/nested/hello/world': {
return render('/nested/[[...optionalName]].js')
}
case '/':
case '/hello':
case '/hello/world': {
return render('/[[...optionalName]].js')
}
default: {
res.statusCode = 404
return res.end('404')
}
}
})
const port = process.env.PORT || 3000
server.listen(port, () => {
console.log('ready on', port)
})
const http = require('http')
const url = require('url')
const fs = require('fs')
const path = require('path')
const server = http.createServer(async (req, res) => {
let { pathname } = url.parse(req.url)
pathname = pathname.replace(/\/$/, '')
let isDataReq = false
if (pathname.startsWith('/_next/data')) {
isDataReq = true
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/')) {
let prom = Promise.resolve()
if (pathname.endsWith('.css')) {
prom = new Promise((resolve) => setTimeout(resolve, 20000))
}
prom.then(() => {
res.write(
fs.readFileSync(
path.join(
__dirname,
'./.next/static/',
decodeURI(pathname.slice('/_next/static/'.length))
),
'utf8'
)
)
return res.end()
})
} else {
if (pathname === '') {
pathname = '/index'
}
const ext = isDataReq ? 'json' : 'html'
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`),
'utf8'
)
)
return res.end()
}
let re
try {
re = require(`./.next/serverless/pages${pathname}`)
} catch {
const d = decodeURI(pathname)
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${d}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${d}.${ext}`),
'utf8'
)
)
return res.end()
}
const routesManifest = require('./.next/routes-manifest.json')
const { dynamicRoutes } = routesManifest
dynamicRoutes.some(({ page, regex }) => {
if (new RegExp(regex).test(pathname)) {
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${page}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${page}.${ext}`),
'utf8'
)
)
res.end()
return true
}
re = require(`./.next/serverless/pages${page}`)
return true
}
return false
})
}
if (!res.finished) {
try {
return await (typeof re.render === 'function'
? re.render(req, res)
: re.default(req, res))
} catch (e) {
console.log('FAIL_FUNCTION', e)
res.statusCode = 500
res.write('FAIL_FUNCTION')
res.end()
}
}
}
})
server.listen(process.env.PORT, () => {
console.log('ready on', process.env.PORT)
})
const http = require('http')
const url = require('url')
const fs = require('fs')
const path = require('path')
const server = http.createServer(async (req, res) => {
let { pathname } = url.parse(req.url)
pathname = pathname.replace(/\/$/, '')
let isDataReq = false
if (pathname.startsWith('/_next/data')) {
isDataReq = true
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/')) {
let prom = Promise.resolve()
if (pathname.endsWith('.css')) {
prom = new Promise((resolve) => setTimeout(resolve, 20000))
}
prom.then(() => {
res.write(
fs.readFileSync(
path.join(
__dirname,
'./.next/static/',
decodeURI(pathname.slice('/_next/static/'.length))
),
'utf8'
)
)
return res.end()
})
} else {
if (pathname === '') {
pathname = '/index'
}
const ext = isDataReq ? 'json' : 'html'
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`),
'utf8'
)
)
return res.end()
}
let re
try {
re = require(`./.next/serverless/pages${pathname}`)
} catch {
const d = decodeURI(pathname)
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${d}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${d}.${ext}`),
'utf8'
)
)
return res.end()
}
const routesManifest = require('./.next/routes-manifest.json')
const { dynamicRoutes } = routesManifest
dynamicRoutes.some(({ page, regex }) => {
if (new RegExp(regex).test(pathname)) {
if (
fs.existsSync(
path.join(__dirname, `./.next/serverless/pages${page}.${ext}`)
)
) {
res.write(
fs.readFileSync(
path.join(__dirname, `./.next/serverless/pages${page}.${ext}`),
'utf8'
)
)
res.end()
return true
}
re = require(`./.next/serverless/pages${page}`)
return true
}
return false
})
}
if (!res.finished) {
try {
return await (typeof re.render === 'function'
? re.render(req, res)
: re.default(req, res))
} catch (e) {
console.log('FAIL_FUNCTION', e)
res.statusCode = 500
res.write('FAIL_FUNCTION')
res.end()
}
}
}
})
server.listen(process.env.PORT, () => {
console.log('ready on', process.env.PORT)
})
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)
})
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)
})
const http = require('http')
const url = require('url')
const render = (pagePath, req, res) => {
const mod = require(`./.next/serverless/pages/${pagePath}`)
return (mod.render || mod.default || mod)(req, res)
}
const { BUILD_ID } = process.env
const server = http.createServer(async (req, res) => {
try {
const { pathname } = url.parse(req.url)
switch (pathname) {
case '/index':
case '/':
case `/_next/data/${BUILD_ID}/index.json`:
return render('index.js', req, res)
case '/another/index':
case '/another':
case `/_next/data/${BUILD_ID}/another/index.json`:
return render('another/index.js', req, res)
default: {
res.statusCode = 404
res.end('not found')
}
}
} catch (err) {
console.error('failed to render', err)
res.statusCode = 500
res.end(err.message)
}
})
server.listen(process.env.PORT, () => {
console.log('ready on', process.env.PORT)
})
const path = require('path')
const http = require('http')
const server = http.createServer(async (req, res) => {
const render = async (page) => {
const mod = require(`./${path.join('.next/serverless/pages/', page)}`)
try {
return await (mod.render || mod.default || mod)(req, res)
} catch (err) {
res.statusCode = 500
return res.end('internal error')
}
}
try {
await render('/[[...slug]].js')
} catch (err) {
console.error('failed to render', err)
res.statusCode = 500
res.end('Internal Error')
}
})
const port = process.env.PORT || 3000
server.listen(port, () => {
console.log('ready on', port)
})
...@@ -769,22 +769,13 @@ export function readNextBuildClientPageFile(appDir, page) { ...@@ -769,22 +769,13 @@ export function readNextBuildClientPageFile(appDir, page) {
export function getPagesManifest(dir) { export function getPagesManifest(dir) {
const serverFile = path.join(dir, '.next/server/pages-manifest.json') const serverFile = path.join(dir, '.next/server/pages-manifest.json')
if (existsSync(serverFile)) { return readJson(serverFile)
return readJson(serverFile)
}
return readJson(path.join(dir, '.next/serverless/pages-manifest.json'))
} }
export function updatePagesManifest(dir, content) { export function updatePagesManifest(dir, content) {
const serverFile = path.join(dir, '.next/server/pages-manifest.json') const serverFile = path.join(dir, '.next/server/pages-manifest.json')
if (existsSync(serverFile)) { return writeFile(serverFile, content)
return writeFile(serverFile, content)
}
return writeFile(
path.join(dir, '.next/serverless/pages-manifest.json'),
content
)
} }
export function getPageFileFromPagesManifest(dir, page) { export function getPageFileFromPagesManifest(dir, page) {
......
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