Skip to content

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

修复开发服务器

WLong8cb523b0995f
diff --git a/server.mjs b/server.mjs
index 705595b..aa1638b 100644
--- a/server.mjs
+++ b/server.mjs
@@ -16,23 +16,33 @@ const password = process.env.PASSWORD || '';
// 启用 CORS
app.use(cors());
-app.get(['/', '/index.html', '/player.html', '/s=*'], async (req, res) => {
+app.get(['/', '/index.html', '/player.html'], async (req, res) => {
try {
let content;
- // 处理搜索路径
- if (req.path.startsWith('/s=')) {
- content = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
- } else {
- switch (req.path) {
- case '/':
- case '/index.html':
- content = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
- break;
- case '/player.html':
- content = fs.readFileSync(path.join(__dirname, 'player.html'), 'utf8');
- break;
- }
+ switch (req.path) {
+ case '/':
+ case '/index.html':
+ content = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
+ break;
+ case '/player.html':
+ content = fs.readFileSync(path.join(__dirname, 'player.html'), 'utf8');
+ break;
+ }
+ if (password !== '') {
+ const sha256 = await sha256Hash(password);
+ content = content.replace('{{PASSWORD}}', sha256);
}
+ res.send(content)
+ } catch (error) {
+ console.error(error)
+ res.status(500).send('读取静态页面失败')
+ }
+})
+
+app.get(['/s=:keyword'], async (req, res) => {
+ try {
+ let content;
+ content = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
if (password !== '') {
const sha256 = await sha256Hash(password);
content = content.replace('{{PASSWORD}}', sha256);
@@ -114,4 +124,3 @@ app.listen(port, () => {
console.log('登录密码为:', password);
}
});
-