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