From 6c4a73f260701b729535e846c1911a29b4c1ca58 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 23 Dec 2020 21:04:03 +0800 Subject: [PATCH] fix: By USE_STATIC_SERVER environment to determine whether to start the static server --- .env.example | 1 + packages/app/.env.example | 1 + packages/plugin-file-manager/src/storages/local.ts | 5 +---- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 548208793..27e6d2153 100644 --- a/.env.example +++ b/.env.example @@ -19,3 +19,4 @@ HTTP_PORT=23000 VERDACCIO_PORT=4873 LOCAL_STORAGE_BASE_URL=http://localhost:23000/uploads +USE_STATIC_SERVER=true diff --git a/packages/app/.env.example b/packages/app/.env.example index 52a7113e6..c2439af5c 100644 --- a/packages/app/.env.example +++ b/packages/app/.env.example @@ -16,3 +16,4 @@ HTTP_PORT=23000 VERDACCIO_PORT=4873 LOCAL_STORAGE_BASE_URL=http://localhost:23000/uploads +USE_STATIC_SERVER=true diff --git a/packages/plugin-file-manager/src/storages/local.ts b/packages/plugin-file-manager/src/storages/local.ts index 263439b95..cb7efa7a3 100644 --- a/packages/plugin-file-manager/src/storages/local.ts +++ b/packages/plugin-file-manager/src/storages/local.ts @@ -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)))); }