Skip to content

Commit a30746e

Browse files
committed
fix: always init context middleware
1 parent 120ec31 commit a30746e

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/http-server/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ export function buildServer(dataFilePath, options = {}) {
3131

3232
const httpServer = polka();
3333

34+
const asyncStoreProperties = {};
3435
if (runFromPayload) {
3536
fs.accessSync(dataFilePath, fs.constants.R_OK | fs.constants.W_OK);
36-
httpServer.use(
37-
middlewares.buildContextMiddleware(dataFilePath, hotReload)
38-
);
37+
asyncStoreProperties.dataFilePath = dataFilePath;
3938
}
4039
else {
4140
appCache.startFromZero = true;
4241
}
42+
httpServer.use(
43+
middlewares.buildContextMiddleware(hotReload, asyncStoreProperties)
44+
);
4345

4446
httpServer.use(middlewares.addStaticFiles);
4547
httpServer.get("/", root.get);

src/http-server/middlewares/context.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { context } from "../../ALS.js";
33
import { ViewBuilder } from "../ViewBuilder.class.js";
44

55
export function buildContextMiddleware(
6-
dataFilePath,
7-
autoReload = false
6+
autoReload = false,
7+
storeProperties = {}
88
) {
99
const viewBuilder = new ViewBuilder({
1010
autoReload
1111
});
1212

1313
return function addContext(_req, _res, next) {
14-
const store = { dataFilePath, viewBuilder };
14+
const store = { ...storeProperties, viewBuilder };
1515
context.run(store, next);
1616
};
1717
}

0 commit comments

Comments
 (0)