Files
hometown/server.js
2026-03-07 19:37:38 +08:00

21 lines
644 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 本地/联合模式:静态资源 + 挂载后端 API。
* 前端请求 /api/* 时由 server/ 提供;前后端分离部署时,前端使用 api.config.json 的 apiBase 指向独立后端。
*/
const path = require('path');
const express = require('express');
const apiApp = require('./server/server.js');
const PORT = process.env.PORT || 3000;
const ROOT = path.resolve(__dirname, process.argv[2] || '.');
const app = express();
app.use(express.json());
app.use('/api', apiApp);
app.use(express.static(ROOT));
app.listen(PORT, () => {
console.log('已启动(静态+API: http://localhost:' + PORT);
});