支持服务端端口直接访问前端

This commit is contained in:
whyour
2021-10-28 23:35:21 +08:00
parent 40bf07d2a4
commit 8f8296ab64
3 changed files with 80 additions and 2 deletions
+11
View File
@@ -10,11 +10,22 @@ import Container from 'typedi';
import OpenService from '../services/open';
import rewrite from 'express-urlrewrite';
import UserService from '../services/user';
import handler from 'serve-handler';
export default ({ app }: { app: Application }) => {
app.enable('trust proxy');
app.use(cors());
app.use((req, res, next) => {
if (req.path.startsWith('/api')) {
next();
} else {
return handler(req, res, {
public: 'dist',
rewrites: [{ source: '**', destination: '/index.html' }],
});
}
});
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));