diff --git a/admin-web/config/config.js b/admin-web/config/config.js index d3e5291c4..95c640a50 100644 --- a/admin-web/config/config.js +++ b/admin-web/config/config.js @@ -4,9 +4,13 @@ import pageRoutes from './router.config'; import webpackPlugin from './plugin.config'; import defaultSettings from '../src/defaultSettings'; import slash from 'slash2'; +import proxy from './proxy'; const { pwa, primaryColor } = defaultSettings; -const { NODE_ENV, APP_TYPE, TEST } = process.env; +const { NODE_ENV, APP_TYPE, TEST, BASE_PATH } = process.env; + +// 用于控制,部署非跟目录下 +const basePath = BASE_PATH ? BASE_PATH : ''; const plugins = [ [ @@ -60,10 +64,8 @@ if (APP_TYPE === 'site') { export default { // add for transfer to umi - // base: '/adsf', - // runtimePublicPath: true, - base: '/admin-web/', - publicPath: '/admin-web/', + base: basePath, + publicPath: basePath, plugins, define: { APP_TYPE: APP_TYPE || '', @@ -83,18 +85,7 @@ export default { '@antv/data-set': 'DataSet', bizcharts: 'BizCharts', }, - proxy: { - '/admin-api/': { - target: 'http://180.167.213.26:18083/', - changeOrigin: true, - pathRewrite: {}, - }, - '/server/api/': { - target: 'https://preview.pro.ant.design/', - changeOrigin: true, - pathRewrite: { '^/server': '' }, - }, - }, + proxy: proxy(NODE_ENV, basePath), ignoreMomentLocale: true, lessLoaderOptions: { javascriptEnabled: true, diff --git a/admin-web/config/proxy/index.js b/admin-web/config/proxy/index.js new file mode 100644 index 000000000..69c5988b3 --- /dev/null +++ b/admin-web/config/proxy/index.js @@ -0,0 +1,31 @@ +// development 和 production + +import path from 'path'; +import proxyDev from './proxy.dev'; +import proxyProd from './proxy.prod'; + +function basePathBuilder(proxys, basePath) { + for (const key in proxys) { + const proxy = proxys[key]; + const pathRewrite = proxy.pathRewrite; + const newPathRewrite = {}; + for (const key2 in pathRewrite) { + const item = pathRewrite[key2]; + newPathRewrite[key2] = path.join(basePath, item); + } + proxy.pathRewrite = newPathRewrite; + } + return proxys; +} + +export default function(NODE_ENV, basePath) { + console.log('development', NODE_ENV === 'development'); + console.log('undefined', NODE_ENV === 'undefined'); + console.log(NODE_ENV); + let proxys = NODE_ENV === 'development' || NODE_ENV === 'undefined' ? proxyDev : proxyProd; + if (basePath) { + proxys = basePathBuilder(proxys, basePath); + } + console.log('proxys------>', proxys); + return proxys; +} diff --git a/admin-web/config/proxy/proxy.dev.js b/admin-web/config/proxy/proxy.dev.js new file mode 100644 index 000000000..f9f2bbdda --- /dev/null +++ b/admin-web/config/proxy/proxy.dev.js @@ -0,0 +1,14 @@ +// 开发环境,的代理配置 + +export default { + '/admin-api/': { + target: 'http://180.167.213.26:18083/', + changeOrigin: true, + pathRewrite: {}, + }, + '/server/api/': { + target: 'https://preview.pro.ant.design/', + changeOrigin: true, + pathRewrite: { '^/server': '' }, + }, +}; diff --git a/admin-web/config/proxy/proxy.prod.js b/admin-web/config/proxy/proxy.prod.js new file mode 100644 index 000000000..968def624 --- /dev/null +++ b/admin-web/config/proxy/proxy.prod.js @@ -0,0 +1,16 @@ +// production 配置文件 + +export default { + '/admin-api/': { + target: 'http://180.167.213.26:18083/', + changeOrigin: true, + pathRewrite: { + '^/admin-api': `/admin-web/admin-api`, + }, + }, + '/server/api/': { + target: 'https://preview.pro.ant.design/', + changeOrigin: true, + pathRewrite: { '^/server': '' }, + }, +}; diff --git a/admin-web/mock/user.js b/admin-web/mock/user.js index 88f85dce1..207378386 100644 --- a/admin-web/mock/user.js +++ b/admin-web/mock/user.js @@ -75,8 +75,8 @@ export default { }, ], 'POST /admin-api/admins/passport/login': (req, res) => { - const { password, username } = req.body; - if (password === 'admin' && username === 'admin') { + const { username } = req.body; + if (username === 'admin') { res.send({ code: 0, data: { @@ -91,7 +91,7 @@ export default { res.send({ code: 1000, data: {}, - message: '账号或密码错误!', + message: '账号或密码错误-mock!', }); }, 'POST /api/register': (req, res) => { diff --git a/admin-web/package.json b/admin-web/package.json index b75d69109..a902d92bf 100644 --- a/admin-web/package.json +++ b/admin-web/package.json @@ -7,7 +7,10 @@ "presite": "cd functions && npm install", "start": "cross-env APP_TYPE=site umi dev", "start:no-mock": "cross-env MOCK=none umi dev", + "start:admin-web": "cross-env BASE_PATH=/admin-web NODE_ENV=development APP_TYPE=site umi dev", + "start:admin-web:no-mock": "cross-env BASE_PATH=/admin-web NODE_ENV=development MOCK=none APP_TYPE=site umi dev", "build": "umi build", + "build:admin-web": "cross-env BASE_PATH=admin-web NODE_ENV=production umi build", "site": "npm run presite && cross-env APP_TYPE=site npm run build && firebase deploy && npm run docker:push", "analyze": "cross-env ANALYZE=1 umi build", "lint:style": "stylelint 'src/**/*.less' --syntax less",