devme commited on
Commit
4050342
·
verified ·
1 Parent(s): b8d7502

Delete server.js

Browse files
Files changed (1) hide show
  1. server.js +0 -69
server.js DELETED
@@ -1,69 +0,0 @@
1
- import express from 'express'
2
- import { loadConfig, isDevMode, getPort } from './config.js'
3
- import { logError } from './logger.js'
4
- import router from './routes.js'
5
-
6
- const app = express();
7
-
8
- app.use(express.json({ limit: '50mb' }));
9
- app.use(express.urlencoded({ extended: true, limit: '50mb' }));
10
-
11
- app.use((req, res, next) => {
12
- res.header('Access-Control-Allow-Origin', '*');
13
- res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
14
- res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-API-Key, anthropic-version');
15
-
16
- if (req.method === 'OPTIONS') {
17
- return res.sendStatus(200);
18
- }
19
- next();
20
- });
21
-
22
- app.use(router);
23
-
24
- app.get('/', (req, res) => {
25
- res.redirect('https://www.bilibili.com/video/BV1SMH5zfEwe/?spm_id_from=333.1007.tianma.1-1-1.click&vd_source=1f3b8eb28230105c578a443fa6481550')
26
- })
27
-
28
-
29
- // 错误处理中间件
30
- app.use((err, req, res, next) => {
31
- logError('未处理的错误', err);
32
- res.status(500).json({
33
- error: '内部服务器错误',
34
- message: isDevMode() ? err.message : undefined
35
- });
36
- });
37
-
38
- (async () => {
39
- try {
40
- loadConfig()
41
- const PORT = getPort()
42
-
43
- const server = app.listen(PORT)
44
- .on('listening', () => {
45
- console.log(`服务器运行在 http://localhost:${PORT}`)
46
- })
47
- .on('error', (err) => {
48
- if (err.code === 'EADDRINUSE') {
49
- console.error(`\n${'='.repeat(80)}`);
50
- console.error(`错误: 端口 ${PORT} 已被占用!`);
51
- console.error('');
52
- console.error('请选择以下选项之一:');
53
- console.error(` 1. 停止使用端口 ${PORT} 的进程:`);
54
- console.error(` lsof -ti:${PORT} | xargs kill`);
55
- console.error('');
56
- console.error(' 2. 使用环境变量更改端口:');
57
- console.error(' export PORT=8080');
58
- console.error(`${'='.repeat(80)}\n`);
59
- process.exit(1);
60
- } else {
61
- logError('启动服务器失败', err);
62
- process.exit(1);
63
- }
64
- });
65
- } catch (error) {
66
- logError('启动服务器失败', error);
67
- process.exit(1);
68
- }
69
- })();