29 lines
722 B
JavaScript
29 lines
722 B
JavaScript
import express from "express";
|
|
import "./window"
|
|
import {render} from "./render";
|
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
|
|
const app = express();
|
|
|
|
app.use('/build', express.static('build'));
|
|
|
|
const targetServer = 'https://www.gitlink.org.cn'; // Java 服务器的地址
|
|
const options = {
|
|
target: targetServer,
|
|
changeOrigin: true, // 允许在请求头中更改主机
|
|
};
|
|
|
|
// 设置代理
|
|
app.use('/api', (req, res) => {
|
|
const proxy = createProxyMiddleware(options);
|
|
proxy(req, res);
|
|
});
|
|
|
|
app.get('*',function (req,res) {
|
|
render(req,res);
|
|
})
|
|
|
|
const port = 3000
|
|
|
|
console.log(`\n==> 🌎 Listening on port ${port}. Open up http://localhost:${port}/ in your browser.\n`)
|
|
app.listen(port); |