fix: By USE_STATIC_SERVER environment to determine whether to start the static server

This commit is contained in:
chenos 2020-12-23 21:04:03 +08:00
parent 4b3d07d51c
commit 6c4a73f260
3 changed files with 3 additions and 4 deletions

View File

@ -19,3 +19,4 @@ HTTP_PORT=23000
VERDACCIO_PORT=4873
LOCAL_STORAGE_BASE_URL=http://localhost:23000/uploads
USE_STATIC_SERVER=true

View File

@ -16,3 +16,4 @@ HTTP_PORT=23000
VERDACCIO_PORT=4873
LOCAL_STORAGE_BASE_URL=http://localhost:23000/uploads
USE_STATIC_SERVER=true

View File

@ -54,10 +54,7 @@ export function middleware(app) {
// 否则都忽略,交给其他 server 来提供(如 nginx/cdn 等)
// TODO(bug): https、端口 80 默认值和其他本地 ip/hostname 的情况未考虑
// TODO 实际应该用 NOCOBASE_ENV 来判断,或者抛给 env 处理
if (url.protocol === 'http:'
&& url.hostname === 'localhost'
&& url.port === process.env.HTTP_PORT
) {
if (process.env.USE_STATIC_SERVER) {
const basePath = url.pathname.startsWith('/') ? url.pathname : `/${url.pathname}`;
app.use(mount(basePath, serve(getDocumentRoot(storage))));
}