Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
aee2fbd4
Commit
aee2fbd4
authored
Apr 14, 2022
by
邓晓峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 代理配置热更新
parent
6ff4ced2
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
20 deletions
+88
-20
config.js
config/config.js
+2
-2
micor.js
config/micor.js
+1
-1
proxy.js
config/proxy.js
+1
-2
index.js
server/index.js
+57
-9
addDevMiddlewares.js
server/middlewares/addDevMiddlewares.js
+9
-0
server.js
server/server.js
+1
-0
cleanRequireCache.js
server/utils/cleanRequireCache.js
+10
-0
micro.js
src/micro.js
+7
-6
No files found.
config/config.js
View file @
aee2fbd4
...
...
@@ -4,7 +4,7 @@ const defaultSetting = require('./defaultSetting');
const
cesiumBuild
=
'../node_modules/cesium/Build/Cesium'
;
const
pkgName
=
require
(
'../package.json'
).
name
;
// eslint-disable-next-line import/order
const
{
REACT_APP
_ENV
}
=
process
.
env
;
const
{
NODE
_ENV
}
=
process
.
env
;
// eslint-disable-next-line import/order
const
path
=
require
(
'path'
);
const
CESIUM_BASE_URL
=
`/
${
pkgName
}
`
;
...
...
@@ -45,7 +45,7 @@ module.exports = {
'Cesium'
,
],
},
proxy
:
proxy
[
REACT_APP_ENV
||
'dev'
],
proxy
:
proxy
[
NODE_ENV
],
// openAPI: {
// requestLibPath: "import { request } from '@wisdom-utils/utils'",
// schemaPath: 'http://192.168.10.150:8777/Publish/OMS/swagger/v1/swagger.json',
...
...
config/micor.js
View file @
aee2fbd4
...
...
@@ -15,7 +15,7 @@ export default {
// },
{
name
:
'civ_water'
,
entry
:
`//
${
window
.
location
.
hostname
}
:808
0
/civ_water`
,
entry
:
`//
${
window
.
location
.
hostname
}
:808
1
/civ_water`
,
container
:
'#micro-container'
,
activeRule
:
'/civbase/civ_water'
,
},
...
...
config/proxy.js
View file @
aee2fbd4
...
...
@@ -4,10 +4,9 @@
// const proxyURL = 'http://192.168.12.47:8082';
const
proxyURL
=
'https://panda-water.cn'
;
module
.
exports
=
{
assetsRoot
:
process
.
env
.
NODE_ENV
!==
'production'
?
proxyURL
:
'./'
,
dev
:
{
dev
elopment
:
{
'/PandaOMS'
:{
target
:
proxyURL
,
changeOrigin
:
true
,
...
...
server/index.js
View file @
aee2fbd4
...
...
@@ -3,7 +3,7 @@ const { writeFileSync, mkdirSync, existsSync } = require('fs');
const
rimraf
=
require
(
'rimraf'
);
const
serveStatic
=
require
(
'serve-static'
);
const
{
resolve
}
=
require
(
'path'
);
const
{
portfinder
,
chalk
,
delay
}
=
require
(
'@umijs/utils'
);
const
{
portfinder
,
chalk
,
delay
,
createDebug
,
chokidar
,
signale
,
glob
}
=
require
(
'@umijs/utils'
);
const
argv
=
require
(
'./argv'
);
const
setup
=
require
(
'./middlewares/frontendMiddleware'
);
const
pkg
=
require
(
'../package.json'
);
...
...
@@ -11,20 +11,19 @@ const config = require('../config/config');
const
mockMiddewares
=
require
(
'./mock'
);
const
emitter
=
require
(
'./event'
);
const
Server
=
require
(
'./server'
);
const
debug
=
createDebug
(
'preset-build-in:proxy:createMiddleware'
);
const
proxyConfig
=
require
(
'../config/proxy'
);
const
loadDotEnv
=
require
(
'./utils/loadDotEnv'
);
const
{
getSchema
}
=
require
(
'./openapi'
);
const
cleanRequireCache
=
require
(
'./utils/cleanRequireCache'
);
(
async
()
=>
{
const
defaultPort
=
process
.
env
.
PORT
||
argv
.
port
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
port
);
const
defaultPort
=
process
.
env
.
PORT
||
argv
.
port
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
port
);
const
port
=
await
portfinder
.
getPortPromise
({
port
:
defaultPort
?
parseInt
(
String
(
defaultPort
),
10
)
:
8080
,
});
const
homename
=
process
.
env
.
HOST
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
host
)
||
'127.0.0.1'
;
const
homename
=
process
.
env
.
HOST
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
host
)
||
'127.0.0.1'
;
console
.
log
(
chalk
.
cyan
(
'Starting the development server...'
));
// process.send && process.send({ type: 'UPDATE_PORT', port });
const
isHTTPS
=
process
.
env
.
HTTPS
||
(
argv
&&
argv
.
https
);
...
...
@@ -81,6 +80,54 @@ const { getSchema } = require('./openapi');
},
);
// proxy config 热更新
const
ignore
=
[
// ignore mock files under node_modules
'node_modules/**'
];
const
cwd
=
process
.
cwd
();
const
proxyWatcherPaths
=
[
...(
glob
.
sync
(
'config/proxy.js'
,
{
cwd
,
ignore
,
})
||
[]),
...(
glob
.
sync
(
'**/proxy.js'
,
{
cwd
,
ignore
,
})
||
[]),
...(
glob
.
sync
(
'.env'
,
{
cwd
,
ignore
,
})
||
[]),
...(
glob
.
sync
(
'.env.local'
,
{
cwd
,
ignore
,
})
||
[])
];
const
watcher
=
chokidar
.
watch
(
proxyWatcherPaths
,
{
ignoreInitial
:
true
,
});
const
errors
=
[];
watcher
.
on
(
'ready'
,
()
=>
debug
(
'Initial scan complete. Ready for changes'
)).
on
(
'all'
,
async
(
event
,
file
)
=>
{
debug
(
`[
${
event
}
]
${
file
}
, reload proxy config`
);
errors
.
splice
(
0
,
errors
.
length
);
cleanRequireCache
(
proxyWatcherPaths
);
// eslint-disable-next-line no-const-assign
if
(
!
errors
.
length
)
{
server
.
setupProxy
&&
server
.
setupProxy
(
proxyConfig
[
process
.
env
.
NODE_ENV
],
true
);
signale
.
success
(
`Proxy config parse success`
);
}
});
process
.
once
(
'SIGINT'
,
async
()
=>
{
await
watcher
.
close
();
});
emitter
.
on
(
'onDevCompileDone'
,
async
()
=>
{
try
{
const
openAPIConfig
=
config
.
openAPI
;
...
...
@@ -96,6 +143,7 @@ const { getSchema } = require('./openapi');
}
});
await
server
.
listen
({
port
,
homename
,
...
...
server/middlewares/addDevMiddlewares.js
View file @
aee2fbd4
...
...
@@ -4,6 +4,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
const
webpackHotMiddleware
=
require
(
'webpack-hot-middleware'
);
const
DevCompileDonePlugin
=
require
(
'../../internals/webpack/plugins/DevCompileDonePlugin'
);
const
emitter
=
require
(
'../event'
);
function
getIgnoredWatchRegExp
()
{
// const absOutputPath = winPath(path.join(process.cwd(), outputPath));
return
process
.
env
.
WATCH_IGNORED
===
'none'
...
...
@@ -29,6 +30,7 @@ module.exports = function addDevMiddlewares(
config
,
{
port
=
8080
,
hostname
=
'127.0.0.1'
},
)
{
if
(
!
config
.
mfsu
)
{
webpackConfig
.
plugins
.
push
(
new
DevCompileDonePlugin
({
...
...
@@ -63,8 +65,15 @@ module.exports = function addDevMiddlewares(
app
.
use
(
middleware
);
app
.
use
(
webpackHotMiddleware
(
compiler
));
const
fs
=
middleware
.
context
.
outputFileSystem
;
app
.
get
(
'*'
,
(
req
,
res
)
=>
{
fs
.
readFile
(
path
.
join
(
compiler
.
outputPath
,
'index.html'
),
(
err
,
file
)
=>
{
if
(
err
)
{
...
...
server/server.js
View file @
aee2fbd4
...
...
@@ -181,6 +181,7 @@ class Server {
},
});
}
return
;
};
let
startIndex
=
null
;
...
...
server/utils/cleanRequireCache.js
0 → 100644
View file @
aee2fbd4
const
{
winPath
}
=
require
(
'@umijs/utils'
)
function
cleanRequireCache
(
paths
)
{
Object
.
keys
(
require
.
cache
).
forEach
(
file
=>
{
if
(
paths
.
some
(
p
=>
winPath
(
file
).
indexOf
(
p
)
>
-
1
))
{
delete
require
.
cache
[
file
];
}
});
};
module
.
exports
=
cleanRequireCache
;
\ No newline at end of file
src/micro.js
View file @
aee2fbd4
...
...
@@ -116,11 +116,11 @@ export const initMicroApps = () => {
const
globalConfig
=
window
.
globalConfig
;
// globalConfig.homepage = globalConfig.homepage && /civweb4/.test(globalConfig.homepage) ? config.homepage.replace(/civweb4\//, ''): globalConfig.homepage;
// actions.offGlobalStateChange();
actions
.
setGlobalState
({
// eslint-disable-next-line no-undef
globalConfig
:
globalConfig
//createStoreage.get('globalConfig'),
});
//
actions.setGlobalState({
//
// eslint-disable-next-line no-undef
//
globalConfig: globalConfig
//
//createStoreage.get('globalConfig'),
//
});
// actions.offGlobalStateChange();
microStore
.
set
(
"event:globalConfig"
,
{
globalConfig
:
globalConfig
,
...
...
@@ -306,7 +306,8 @@ window.app.define('kit_global_config', require.context('../node_modules/kit_glob
window
.
app
.
define
(
'@wisdom-utils/utils'
,
require
.
context
(
'../node_modules/@wisdom-utils/utils/lib'
,
true
,
/^.
\/(
lib
\/)?[^\/]
+
\.
js$/
),
'index.js'
);
window
.
app
.
define
(
'@wisdom-utils/runtime'
,
require
.
context
(
'../node_modules/@wisdom-utils/runtime/lib'
,
true
,
/^.
\/(
lib
\/)?[^\/]
+
\.
js$/
),
'index.js'
);
window
.
app
.
define
(
'@wisdom-utils/components'
,
require
.
context
(
'../node_modules/@wisdom-utils/components/lib'
,
true
,
/^.
\/(
lib
\/)?[^\/]
+
\.
js$/
),
'index.js'
);
window
.
app
.
define
(
'axios'
,
require
.
context
(
'../node_modules/axios/lib'
,
true
,
/^.
\/(
lib
\/)?[^\/]
+
\.
js$/
),
'axios.js'
);
window
.
app
.
define
(
'js-base64'
,
require
.
context
(
'../node_modules/js-base64'
,
true
,
/
[^\/]
+
\.
js$/
),
'base64.js'
);
/**
* arcgismap
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment