Skip to content

Commit

Permalink
feat: 支持在服务器上挂载多个 static 目录
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongzhi107 committed Dec 5, 2019
1 parent bcb5048 commit 7923b8e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/runtime/utils/addStatic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { existsSync } from 'fs';
import express from 'express';

export default (app) => {
const {
DACE_PATH_STATIC,
DACE_STATIC,
DACE_PUBLIC_PATH,
DACE_PATH_CLIENT_DIST
} = process.env;
Expand All @@ -12,7 +11,11 @@ export default (app) => {
app.use(express.static(DACE_PATH_CLIENT_DIST));
}

if (DACE_PATH_STATIC !== '' && existsSync(DACE_PATH_STATIC)) {
app.use(express.static(DACE_PATH_STATIC));
if (DACE_STATIC !== '') {
DACE_STATIC.split(',').map(dir => dir.trim()).forEach((dir) => {
// dir 为相对程序启动入口文件的相对目录
app.use(express.static(dir));
});
console.log(`set static success, the root directory is ${DACE_STATIC}`);
}
};

0 comments on commit 7923b8e

Please sign in to comment.