feat: 增加resolve
This commit is contained in:
parent
a73a613bda
commit
daac931994
@ -3,7 +3,7 @@ import express from 'express'
|
|||||||
import cors from 'cors'
|
import cors from 'cors'
|
||||||
import grpc from '@grpc/grpc-js'
|
import grpc from '@grpc/grpc-js'
|
||||||
import protoLoader from '@grpc/proto-loader'
|
import protoLoader from '@grpc/proto-loader'
|
||||||
import { resolve } from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
|
|
||||||
@ -247,18 +247,18 @@ const PORT = process.env.VITE_SERVICE_PORT || 3000;
|
|||||||
|
|
||||||
// ============ 生产环境:托管 Vite 构建产物 ============
|
// ============ 生产环境:托管 Vite 构建产物 ============
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
const distPath = resolve(__dirname, '../dist');
|
const distPath = path.resolve(__dirname, '../dist');
|
||||||
|
|
||||||
// 托管静态文件
|
// 托管静态文件
|
||||||
app.use(express.static(distPath));
|
app.use(express.static(distPath));
|
||||||
|
|
||||||
// SPA 回退:所有非 API 请求返回 index.html
|
// SPA 回退:所有非 API 请求返回 index.html
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
res.sendFile(resolve(distPath, 'index.html'));
|
res.sendFile(path.resolve(distPath, 'index.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('*', (req, res) => {
|
app.post('*', (req, res) => {
|
||||||
res.sendFile(resolve(distPath, 'index.html'));
|
res.sendFile(path.resolve(distPath, 'index.html'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user