Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of next.js custom server #452

Merged
merged 10 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"license": "MIT",
"scripts": {
"build": "yarn prisma generate && concurrently \"yarn:build:*\" && rimraf ./.next/cache",
"start": "yarn waitForDb && yarn prisma migrate deploy && NODE_ENV=production node ./server.js",
"start": "yarn waitForDb && yarn prisma migrate deploy && next start",
"dev": "yarn prisma generate && yarn waitForDb && yarn prisma db push --skip-generate && concurrently \"yarn:dev:*\"",
"lint": "next lint && prettier --check .",
"fix": "next lint --fix && prettier --write .",
"prisma": "prisma",
"build:next": "next build",
"build:react-devtools": "rimraf ./public/reactDevtools && esbuild ./reactDevtools/bootstrap.ts --target=es6 --bundle --outdir=./public/reactDevtools",
"build:typings": "ts-node ./scripts/typings.ts",
"dev:next": "node ./server.js",
"dev:next": "next dev",
"dev:react-devtools": "yarn build:react-devtools --watch",
"dev:typings": "yarn build:typings",
"dev:prisma": "prisma generate --watch",
Expand Down
30 changes: 30 additions & 0 deletions packages/toolpad-app/pages/_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NextRequest, NextResponse } from 'next/server';
import config from '../src/server/config';

const BASIC_AUTH_WHITELIST = new Set(['/health-check']);

export function middleware(req: NextRequest) {
const { pathname } = new URL(req.url);

if (!config.basicAuthUser || BASIC_AUTH_WHITELIST.has(pathname)) {
return NextResponse.next();
}

const basicAuth = req.headers.get('authorization');

if (basicAuth) {
const auth = basicAuth.split(' ')[1];
const [user, pwd] = Buffer.from(auth, 'base64').toString().split(':');

if (user === config.basicAuthUser && pwd === config.basicAuthPassword) {
return NextResponse.next();
}
}

return new Response(null, {
status: 401,
headers: {
'WWW-Authenticate': 'Basic realm="Secure Area"',
},
});
}
58 changes: 0 additions & 58 deletions packages/toolpad-app/server.js

This file was deleted.