Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const path = require('path');
|
| 3 |
+
const app = express();
|
| 4 |
+
const port = process.env.PORT || 8080;
|
| 5 |
+
|
| 6 |
+
// 提供静态文件(前端文件)
|
| 7 |
+
app.use(express.static(path.join(__dirname, 'public')));
|
| 8 |
+
|
| 9 |
+
// 提供配置信息的 API 接口
|
| 10 |
+
app.get('/api/config', (req, res) => {
|
| 11 |
+
const usernames = process.env.HUGGINGFACE_USERNAMES || '';
|
| 12 |
+
res.json({ usernames });
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
// 处理其他请求,重定向到 index.html
|
| 16 |
+
app.get('*', (req, res) => {
|
| 17 |
+
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
app.listen(port, () => {
|
| 21 |
+
console.log(`Server running on port ${port}`);
|
| 22 |
+
console.log(`Usernames configured: ${process.env.HUGGINGFACE_USERNAMES || 'None'}`);
|
| 23 |
+
});
|