Skip to content

一分钟搭建影视站,支持Docker等部署方式

修复vercel部署问题

developer72261bbdf88c
diff --git a/middleware.js b/middleware.js
index 6020f3f..396be52 100644
--- a/middleware.js
+++ b/middleware.js
@@ -1,43 +1,42 @@
// Vercel Middleware to inject environment variables
-import { NextResponse } from 'next/server';
+export default async function middleware(request) {
+ // Get the URL from the request
+ const url = new URL(request.url);
+
+ // Only process HTML pages
+ const isHtmlPage = url.pathname.endsWith('.html') || url.pathname.endsWith('/');
+ if (!isHtmlPage) {
+ return; // Let the request pass through unchanged
+ }
-export default function middleware(request) {
- // Get the original response
- const response = NextResponse.next();
+ // Fetch the original response
+ const response = await fetch(request);
- // Modify this to intercept HTML responses only
- // This is a simplified example - in production you'd want more robust content-type checking
- if (request.nextUrl.pathname.endsWith('.html') || request.nextUrl.pathname.endsWith('/')) {
- response.then(async (res) => {
- const contentType = res.headers.get('content-type');
-
- if (contentType && contentType.includes('text/html')) {
- // Get the HTML content
- const originalHtml = await res.text();
-
- // Replace the placeholder with actual environment variable
- // If PASSWORD is not set, replace with empty string
- const password = process.env.PASSWORD || '';
- const modifiedHtml = originalHtml.replace(
- 'window.__ENV__.PASSWORD = "{{PASSWORD}}";',
- `window.__ENV__.PASSWORD = "${password}";`
- );
-
- // Create a new response with the modified HTML
- return new Response(modifiedHtml, {
- status: res.status,
- statusText: res.statusText,
- headers: res.headers
- });
- }
-
- return res;
- });
+ // Check if it's an HTML response
+ const contentType = response.headers.get('content-type') || '';
+ if (!contentType.includes('text/html')) {
+ return response; // Return the original response if not HTML
}
+
+ // Get the HTML content
+ const originalHtml = await response.text();
+
+ // Replace the placeholder with actual environment variable
+ // If PASSWORD is not set, replace with empty string
+ const password = process.env.PASSWORD || '';
+ const modifiedHtml = originalHtml.replace(
+ 'window.__ENV__.PASSWORD = "{{PASSWORD}}";',
+ `window.__ENV__.PASSWORD = "${password}";`
+ );
- return response;
+ // Create a new response with the modified HTML
+ return new Response(modifiedHtml, {
+ status: response.status,
+ statusText: response.statusText,
+ headers: response.headers
+ });
}
export const config = {
- matcher: ['/', '/((?!api|_next/static|favicon.ico).*)'],
+ matcher: ['/', '/((?!api|_next/static|_vercel|favicon.ico).*)'],
};
\ No newline at end of file
diff --git a/package.json b/package.json
index 1cb6cf7..227023e 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "1.1.0",
"description": "免费在线视频搜索与观看平台",
"private": true,
+ "type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},