🔀 Merge pull request #487 from SR3u/feature/freebsd-support

Updated: Next.js 12.1.6 -> 12.2.0, thanks @SR3u !
This commit is contained in:
Thomas Camlong
2022-11-02 16:52:59 +09:00
committed by GitHub
6 changed files with 113 additions and 79 deletions

23
src/middleware.ts Normal file
View File

@@ -0,0 +1,23 @@
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
// eslint-disable-next-line consistent-return
export function middleware(req: NextRequest, ev: NextFetchEvent) {
const isCorrectPassword = req.cookies.get('password') === process.env.PASSWORD;
const url = req.nextUrl.clone();
const skipURL = url.pathname && (
url.pathname.includes('login') || url.pathname === ('/api/configs/tryPassword') || (
url.pathname.includes('/_next/') && !url.pathname.includes('/pages/')
) ||
url.pathname === '/favicon.ico' ||
url.pathname === '/404' ||
url.pathname.includes('pages/_app')
);
if (
!skipURL &&
!isCorrectPassword &&
process.env.PASSWORD
) {
url.pathname = '/login';
return NextResponse.rewrite(url);
}
}

View File

@@ -1,16 +0,0 @@
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
// eslint-disable-next-line consistent-return
export function middleware(req: NextRequest, ev: NextFetchEvent) {
const isCorrectPassword = req.cookies.password === process.env.PASSWORD;
const url = req.nextUrl.clone();
if (
!isCorrectPassword &&
url.pathname !== '/login' &&
process.env.PASSWORD &&
url.pathname !== '/api/configs/tryPassword'
) {
url.pathname = '/login';
return NextResponse.rewrite(url);
}
}

View File

@@ -14,7 +14,7 @@ function Post(req: NextApiRequest, res: NextApiResponse) {
}
export default async (req: NextApiRequest, res: NextApiResponse) => {
// Filter out if the reuqest is a POST or a GET
// Filter out if the request is a POST or a GET
if (req.method === 'POST') {
return Post(req, res);
}