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
3 years ago
by
邓晓峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 代理配置热更新
parent
6ff4ced2
master
dev
devNew
feat/layout-flat
patch-1
soundai
test
zhongyi
No related merge requests found
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');
...
@@ -4,7 +4,7 @@ const defaultSetting = require('./defaultSetting');
const
cesiumBuild
=
'../node_modules/cesium/Build/Cesium'
;
const
cesiumBuild
=
'../node_modules/cesium/Build/Cesium'
;
const
pkgName
=
require
(
'../package.json'
).
name
;
const
pkgName
=
require
(
'../package.json'
).
name
;
// eslint-disable-next-line import/order
// eslint-disable-next-line import/order
const
{
REACT_APP
_ENV
}
=
process
.
env
;
const
{
NODE
_ENV
}
=
process
.
env
;
// eslint-disable-next-line import/order
// eslint-disable-next-line import/order
const
path
=
require
(
'path'
);
const
path
=
require
(
'path'
);
const
CESIUM_BASE_URL
=
`/
${
pkgName
}
`
;
const
CESIUM_BASE_URL
=
`/
${
pkgName
}
`
;
...
@@ -45,7 +45,7 @@ module.exports = {
...
@@ -45,7 +45,7 @@ module.exports = {
'Cesium'
,
'Cesium'
,
],
],
},
},
proxy
:
proxy
[
REACT_APP_ENV
||
'dev'
],
proxy
:
proxy
[
NODE_ENV
],
// openAPI: {
// openAPI: {
// requestLibPath: "import { request } from '@wisdom-utils/utils'",
// requestLibPath: "import { request } from '@wisdom-utils/utils'",
// schemaPath: 'http://192.168.10.150:8777/Publish/OMS/swagger/v1/swagger.json',
// schemaPath: 'http://192.168.10.150:8777/Publish/OMS/swagger/v1/swagger.json',
...
...
This diff is collapsed.
Click to expand it.
config/micor.js
View file @
aee2fbd4
...
@@ -15,7 +15,7 @@ export default {
...
@@ -15,7 +15,7 @@ export default {
// },
// },
{
{
name
:
'civ_water'
,
name
:
'civ_water'
,
entry
:
`//
${
window
.
location
.
hostname
}
:808
0
/civ_water`
,
entry
:
`//
${
window
.
location
.
hostname
}
:808
1
/civ_water`
,
container
:
'#micro-container'
,
container
:
'#micro-container'
,
activeRule
:
'/civbase/civ_water'
,
activeRule
:
'/civbase/civ_water'
,
},
},
...
...
This diff is collapsed.
Click to expand it.
config/proxy.js
View file @
aee2fbd4
...
@@ -4,10 +4,9 @@
...
@@ -4,10 +4,9 @@
// const proxyURL = 'http://192.168.12.47:8082';
// const proxyURL = 'http://192.168.12.47:8082';
const
proxyURL
=
'https://panda-water.cn'
;
const
proxyURL
=
'https://panda-water.cn'
;
module
.
exports
=
{
module
.
exports
=
{
assetsRoot
:
process
.
env
.
NODE_ENV
!==
'production'
?
proxyURL
:
'./'
,
assetsRoot
:
process
.
env
.
NODE_ENV
!==
'production'
?
proxyURL
:
'./'
,
dev
:
{
dev
elopment
:
{
'/PandaOMS'
:{
'/PandaOMS'
:{
target
:
proxyURL
,
target
:
proxyURL
,
changeOrigin
:
true
,
changeOrigin
:
true
,
...
...
This diff is collapsed.
Click to expand it.
server/index.js
View file @
aee2fbd4
...
@@ -3,7 +3,7 @@ const { writeFileSync, mkdirSync, existsSync } = require('fs');
...
@@ -3,7 +3,7 @@ const { writeFileSync, mkdirSync, existsSync } = require('fs');
const
rimraf
=
require
(
'rimraf'
);
const
rimraf
=
require
(
'rimraf'
);
const
serveStatic
=
require
(
'serve-static'
);
const
serveStatic
=
require
(
'serve-static'
);
const
{
resolve
}
=
require
(
'path'
);
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
argv
=
require
(
'./argv'
);
const
setup
=
require
(
'./middlewares/frontendMiddleware'
);
const
setup
=
require
(
'./middlewares/frontendMiddleware'
);
const
pkg
=
require
(
'../package.json'
);
const
pkg
=
require
(
'../package.json'
);
...
@@ -11,20 +11,19 @@ const config = require('../config/config');
...
@@ -11,20 +11,19 @@ const config = require('../config/config');
const
mockMiddewares
=
require
(
'./mock'
);
const
mockMiddewares
=
require
(
'./mock'
);
const
emitter
=
require
(
'./event'
);
const
emitter
=
require
(
'./event'
);
const
Server
=
require
(
'./server'
);
const
Server
=
require
(
'./server'
);
const
debug
=
createDebug
(
'preset-build-in:proxy:createMiddleware'
);
const
proxyConfig
=
require
(
'../config/proxy'
);
const
loadDotEnv
=
require
(
'./utils/loadDotEnv'
);
const
loadDotEnv
=
require
(
'./utils/loadDotEnv'
);
const
{
getSchema
}
=
require
(
'./openapi'
);
const
{
getSchema
}
=
require
(
'./openapi'
);
const
cleanRequireCache
=
require
(
'./utils/cleanRequireCache'
);
(
async
()
=>
{
(
async
()
=>
{
const
defaultPort
=
const
defaultPort
=
process
.
env
.
PORT
||
argv
.
port
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
port
);
process
.
env
.
PORT
||
argv
.
port
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
port
);
const
port
=
await
portfinder
.
getPortPromise
({
const
port
=
await
portfinder
.
getPortPromise
({
port
:
defaultPort
?
parseInt
(
String
(
defaultPort
),
10
)
:
8080
,
port
:
defaultPort
?
parseInt
(
String
(
defaultPort
),
10
)
:
8080
,
});
});
const
homename
=
const
homename
=
process
.
env
.
HOST
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
host
)
||
'127.0.0.1'
;
process
.
env
.
HOST
||
(
config
&&
config
.
devServer
&&
config
.
devServer
.
host
)
||
'127.0.0.1'
;
console
.
log
(
chalk
.
cyan
(
'Starting the development server...'
));
console
.
log
(
chalk
.
cyan
(
'Starting the development server...'
));
// process.send && process.send({ type: 'UPDATE_PORT', port });
// process.send && process.send({ type: 'UPDATE_PORT', port });
const
isHTTPS
=
process
.
env
.
HTTPS
||
(
argv
&&
argv
.
https
);
const
isHTTPS
=
process
.
env
.
HTTPS
||
(
argv
&&
argv
.
https
);
...
@@ -81,6 +80,54 @@ const { getSchema } = require('./openapi');
...
@@ -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
()
=>
{
emitter
.
on
(
'onDevCompileDone'
,
async
()
=>
{
try
{
try
{
const
openAPIConfig
=
config
.
openAPI
;
const
openAPIConfig
=
config
.
openAPI
;
...
@@ -96,6 +143,7 @@ const { getSchema } = require('./openapi');
...
@@ -96,6 +143,7 @@ const { getSchema } = require('./openapi');
}
}
});
});
await
server
.
listen
({
await
server
.
listen
({
port
,
port
,
homename
,
homename
,
...
...
This diff is collapsed.
Click to expand it.
server/middlewares/addDevMiddlewares.js
View file @
aee2fbd4
...
@@ -4,6 +4,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
...
@@ -4,6 +4,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
const
webpackHotMiddleware
=
require
(
'webpack-hot-middleware'
);
const
webpackHotMiddleware
=
require
(
'webpack-hot-middleware'
);
const
DevCompileDonePlugin
=
require
(
'../../internals/webpack/plugins/DevCompileDonePlugin'
);
const
DevCompileDonePlugin
=
require
(
'../../internals/webpack/plugins/DevCompileDonePlugin'
);
const
emitter
=
require
(
'../event'
);
const
emitter
=
require
(
'../event'
);
function
getIgnoredWatchRegExp
()
{
function
getIgnoredWatchRegExp
()
{
// const absOutputPath = winPath(path.join(process.cwd(), outputPath));
// const absOutputPath = winPath(path.join(process.cwd(), outputPath));
return
process
.
env
.
WATCH_IGNORED
===
'none'
return
process
.
env
.
WATCH_IGNORED
===
'none'
...
@@ -29,6 +30,7 @@ module.exports = function addDevMiddlewares(
...
@@ -29,6 +30,7 @@ module.exports = function addDevMiddlewares(
config
,
config
,
{
port
=
8080
,
hostname
=
'127.0.0.1'
},
{
port
=
8080
,
hostname
=
'127.0.0.1'
},
)
{
)
{
if
(
!
config
.
mfsu
)
{
if
(
!
config
.
mfsu
)
{
webpackConfig
.
plugins
.
push
(
webpackConfig
.
plugins
.
push
(
new
DevCompileDonePlugin
({
new
DevCompileDonePlugin
({
...
@@ -63,8 +65,15 @@ module.exports = function addDevMiddlewares(
...
@@ -63,8 +65,15 @@ module.exports = function addDevMiddlewares(
app
.
use
(
middleware
);
app
.
use
(
middleware
);
app
.
use
(
webpackHotMiddleware
(
compiler
));
app
.
use
(
webpackHotMiddleware
(
compiler
));
const
fs
=
middleware
.
context
.
outputFileSystem
;
const
fs
=
middleware
.
context
.
outputFileSystem
;
app
.
get
(
'*'
,
(
req
,
res
)
=>
{
app
.
get
(
'*'
,
(
req
,
res
)
=>
{
fs
.
readFile
(
path
.
join
(
compiler
.
outputPath
,
'index.html'
),
(
err
,
file
)
=>
{
fs
.
readFile
(
path
.
join
(
compiler
.
outputPath
,
'index.html'
),
(
err
,
file
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
server/server.js
View file @
aee2fbd4
...
@@ -181,6 +181,7 @@ class Server {
...
@@ -181,6 +181,7 @@ class Server {
},
},
});
});
}
}
return
;
};
};
let
startIndex
=
null
;
let
startIndex
=
null
;
...
...
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
src/micro.js
View file @
aee2fbd4
...
@@ -116,11 +116,11 @@ export const initMicroApps = () => {
...
@@ -116,11 +116,11 @@ export const initMicroApps = () => {
const
globalConfig
=
window
.
globalConfig
;
const
globalConfig
=
window
.
globalConfig
;
// globalConfig.homepage = globalConfig.homepage && /civweb4/.test(globalConfig.homepage) ? config.homepage.replace(/civweb4\//, ''): globalConfig.homepage;
// globalConfig.homepage = globalConfig.homepage && /civweb4/.test(globalConfig.homepage) ? config.homepage.replace(/civweb4\//, ''): globalConfig.homepage;
// actions.offGlobalStateChange();
// actions.offGlobalStateChange();
actions
.
setGlobalState
({
//
actions.setGlobalState({
// eslint-disable-next-line no-undef
//
// eslint-disable-next-line no-undef
globalConfig
:
globalConfig
//
globalConfig: globalConfig
//createStoreage.get('globalConfig'),
//
//createStoreage.get('globalConfig'),
});
//
});
// actions.offGlobalStateChange();
// actions.offGlobalStateChange();
microStore
.
set
(
"event:globalConfig"
,
{
microStore
.
set
(
"event:globalConfig"
,
{
globalConfig
:
globalConfig
,
globalConfig
:
globalConfig
,
...
@@ -306,7 +306,8 @@ window.app.define('kit_global_config', require.context('../node_modules/kit_glob
...
@@ -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/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/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
(
'@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
* arcgismap
*/
*/
...
...
This diff is collapsed.
Click to expand it.
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