mirror of
https://mirror.ghproxy.com/https://github.com/CxJuice/ScWeb_Chinese_Translate.git
synced 2024-12-23 01:33:45 +08:00
Update server.js
This commit is contained in:
parent
2a05782ee5
commit
3aae4fca39
@ -1,14 +1,11 @@
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const cors = require('cors'); // <-- 导入 cors 中间件
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const JSON_FOLDER_PATH = path.join(__dirname, 'json');
|
||||
|
||||
app.use(cors()); // <-- 使用 cors 中间件以允许所有来源
|
||||
|
||||
// 获取文件夹内的所有 JSON 文件
|
||||
app.get('/json-files', (req, res) => {
|
||||
fs.readdir(JSON_FOLDER_PATH, (err, files) => {
|
||||
@ -42,4 +39,4 @@ app.get('/json-files/:filename', (req, res) => {
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user