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
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
// import express from 'express'
|
|
import { join, dirname } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { createServer } from 'node:http'
|
|
|
|
// output: "export" mode was originally designed to work seamlessly with the
|
|
// "serve" package, which uses "server-handler" internally. It has built-in
|
|
// conventions for things like .html extensions and trailing slashes. Apps that
|
|
// use a different server like ngnix need configuration to match this behavior.
|
|
// TODO: We should improve our documentation around this.
|
|
import handler from 'serve-handler'
|
|
|
|
const OUT_DIR = join(dirname(fileURLToPath(import.meta.url)), 'out')
|
|
|
|
export const server = createServer((request, response) => {
|
|
// Redirect /redirect-to-target-page to /target-page. Notice that we only have
|
|
// to redirect the path of the page, not any other resources.
|
|
if (request.url === '/redirect-to-target-page') {
|
|
console.log('Redirecting to /target-page')
|
|
response.writeHead(302, { Location: '/target-page' })
|
|
response.end()
|
|
return
|
|
}
|
|
|
|
// Rewrite /rewrite-to-target-page to /target-page
|
|
// NOTE: This simulates a rewrite using a proxy, which is not something we
|
|
// officially support or document. It's just here to illustrate how it would
|
|
// be done in theory.
|
|
if (/^\/rewrite-to-target-page\/?[^/]*$/.test(request.url)) {
|
|
const newUrl = request.url.replace(
|
|
'/rewrite-to-target-page',
|
|
'/target-page'
|
|
)
|
|
console.log(`Rewriting ${request.url} to ${newUrl}`)
|
|
request.url = newUrl
|
|
}
|
|
|
|
return handler(request, response, {
|
|
public: OUT_DIR,
|
|
})
|
|
})
|