From 1c143b8e77c3f0eab11ea22111be552c5426dd7c Mon Sep 17 00:00:00 2001 From: pjmw9izve <2308014474@qq.com> Date: Mon, 7 Oct 2024 22:24:52 +0800 Subject: [PATCH] ADD file via upload --- server.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 server.js diff --git a/server.js b/server.js new file mode 100644 index 0000000..5554dc3 --- /dev/null +++ b/server.js @@ -0,0 +1,26 @@ +const express = require('express'); +const path = require('path'); +const bodyParser = require('body-parser'); +const router = require('./router'); +const app = express(); + +// 中间件 +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); + +// API 路由 +app.use('/api', router); + +// 静态文件 +app.use(express.static(path.join(__dirname, 'public'))); + +// 处理 SPA 路由 +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, 'public', 'index.html')); +}); + +// 启动服务器 +const PORT = process.env.PORT || 3000; +app.listen(PORT, () => { + console.log(`Server running on port ${PORT}`); +});