🧐 问题描述 | Problem description
项目build部署后,无法登录。本地使用yarn start
或者npm run start
能正常登录。部署后无法登录, Response status:404 。
浏览器响应状态:
请求 URL: http://localhost:8000/api/login/account?token%20=%20123
请求方法: POST
状态代码: 404 Not Found
版本:ant-design-pro@6.0.0
💻 部署代码 node run_server.js
const express = require('express');
const app = express();
const path = require('path');
// 使用path.join获取绝对路径
const buildPath = path.join(__dirname, 'dist');
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server started on http://localhost:${port}`);
});
💻 proxy.ts
export default {
test: {
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
'/api/': {
target: 'https://proapi.azurewebsites.net',
changeOrigin: true,
pathRewrite: { '^': '' },
},
},
pre: {
'/api/': {
target: 'your pre url',
changeOrigin: true,
pathRewrite: { '^': '' },
},
},
};
💻 config.ts
// https://umijs.org/config/
import { defineConfig } from '@umijs/max';
import { join } from 'path';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import routes from './routes';
const { REACT_APP_ENV = 'dev' } = process.env;
export default defineConfig({
history: { type: 'hash' }, // 默认是 browser
hash: true,
routes,
theme: {
// 如果不想要 configProvide 动态设置主题需要把这个设置为 default
// 只有设置为 variable, 才能使用 configProvide 动态设置主色调
'root-entry-name': 'variable',
},
ignoreMomentLocale: true,
proxy: proxy[REACT_APP_ENV as keyof typeof proxy],
fastRefresh: true,
model: {},
initialState: {},
title: 'AntDesign',
layout: {
locale: true,
...defaultSettings,
},
moment2dayjs: {
preset: 'antd',
plugins: ['duration'],
},
antd: {},
request: {},
access: {},
headScripts: [
// 解决首次加载时白屏的问题
{
src: '/scripts/loading.js',
async: true,
},
],
//================ pro 插件配置 =================
presets: ['umi-presets-pro'],
openAPI: [
{
requestLibPath: "import { request } from '@umijs/max'",
// 或者使用在线的版本
// schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
schemaPath: join(__dirname, 'oneapi.json'),
mock: false,
},
{
requestLibPath: "import { request } from '@umijs/max'",
schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
projectName: 'swagger',
},
],
mfsu: {
strategy: 'normal',
},
esbuildMinifyIIFE: true,
requestRecord: {},
});