Refactor middleware.ts by removing 'process'

This commit is contained in:
ajnart
2023-11-08 20:41:36 +01:00
parent ce30bffb6a
commit a36813da39

View File

@@ -1,7 +1,6 @@
import Consola from 'consola'; import Consola from 'consola';
import fs from 'fs/promises'; import fs from 'fs/promises';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { env } from 'process';
import { getUrl } from './tools/server/url'; import { getUrl } from './tools/server/url';
import { client } from './utils/api'; import { client } from './utils/api';
@@ -27,7 +26,7 @@ export async function middleware(req: NextRequest) {
} }
// Do not redirect if we are on Vercel // Do not redirect if we are on Vercel
if (env.VERCEL) { if (process.env.VERCEL) {
return NextResponse.next(); return NextResponse.next();
} }
@@ -50,11 +49,11 @@ const shouldRedirectToOnboard = async (): Promise<boolean> => {
return cachedUserCount === 0; return cachedUserCount === 0;
}; };
if (!env.DATABASE_URL?.startsWith('file:')) { if (!process.env.DATABASE_URL?.startsWith('file:')) {
return await cacheAndGetUserCount(); return await cacheAndGetUserCount();
} }
const fileUri = env.DATABASE_URL.substring(4); const fileUri = process.env.DATABASE_URL.substring(4);
try { try {
await fs.access(fileUri, fs.constants.W_OK); await fs.access(fileUri, fs.constants.W_OK);
return await cacheAndGetUserCount(); return await cacheAndGetUserCount();