qumra-engine 2.0.163 → 2.0.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +29 -23
- package/package.json +1 -1
package/dist/middleware.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App, CacheGetter, CacheSetter, TMode } from
|
|
1
|
+
import { App, CacheGetter, CacheSetter, TMode } from './types/sharedTypes';
|
|
2
2
|
interface IStartEngine {
|
|
3
3
|
renderApi?: string | null;
|
|
4
4
|
mode: TMode;
|
|
@@ -10,5 +10,5 @@ interface IStartEngine {
|
|
|
10
10
|
currentApp?: App;
|
|
11
11
|
market?: string;
|
|
12
12
|
}
|
|
13
|
-
declare const startEngine: ({ renderApi, mode, getRender, setRender, port, themesRepo, themeId, currentApp, market
|
|
13
|
+
declare const startEngine: ({ renderApi, mode, getRender, setRender, port, themesRepo, themeId, currentApp, market }: IStartEngine) => Promise<void>;
|
|
14
14
|
export default startEngine;
|
package/dist/middleware.js
CHANGED
|
@@ -22,32 +22,34 @@ const extensions_middleware_1 = require("./middleware/extensions.middleware");
|
|
|
22
22
|
const locals_middleware_1 = require("./middleware/locals.middleware");
|
|
23
23
|
const setGlobals_middleware_1 = require("./middleware/setGlobals.middleware");
|
|
24
24
|
const locals_1 = require("./store/locals");
|
|
25
|
-
const
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const path_2 = __importDefault(require("path"));
|
|
27
|
+
const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000, themesRepo, themeId = null, currentApp, market }) => {
|
|
26
28
|
try {
|
|
27
29
|
const app = (0, express_1.default)();
|
|
28
|
-
const isProduction = process.env.NODE_ENV ===
|
|
30
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
29
31
|
app.use((0, cookie_parser_1.default)());
|
|
30
32
|
app.use(express_1.default.urlencoded({ extended: true }));
|
|
31
33
|
app.use(express_1.default.json());
|
|
32
|
-
app.use((0, morgan_1.default)(
|
|
33
|
-
app.set(
|
|
34
|
-
app.set(
|
|
35
|
-
app.get(
|
|
36
|
-
console.log(
|
|
37
|
-
return res.status(200).send(
|
|
34
|
+
app.use((0, morgan_1.default)('dev'));
|
|
35
|
+
app.set('view engine', 'nunjucks');
|
|
36
|
+
app.set('trust proxy', 1);
|
|
37
|
+
app.get('/health', (_, res) => {
|
|
38
|
+
console.log('🚀 Health check OK');
|
|
39
|
+
return res.status(200).send('OK');
|
|
38
40
|
});
|
|
39
41
|
app.use((req, res, next) => {
|
|
40
42
|
res.locals.showDevTools = req.query.showDevTools ?? false;
|
|
41
|
-
const isIframe = req.query.iframe ===
|
|
43
|
+
const isIframe = req.query.iframe === '1' || req.headers['sec-fetch-dest'] === 'iframe';
|
|
42
44
|
res.locals.isIframe = !!isIframe;
|
|
43
45
|
next();
|
|
44
46
|
});
|
|
45
47
|
app.use((0, express_session_1.default)({
|
|
46
|
-
secret: process.env.SESSION_SECRET ||
|
|
48
|
+
secret: process.env.SESSION_SECRET || 'your-secret-key',
|
|
47
49
|
resave: false,
|
|
48
50
|
saveUninitialized: false,
|
|
49
51
|
cookie: {
|
|
50
|
-
sameSite:
|
|
52
|
+
sameSite: 'none',
|
|
51
53
|
secure: isProduction,
|
|
52
54
|
httpOnly: true,
|
|
53
55
|
partitioned: true,
|
|
@@ -60,7 +62,7 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
60
62
|
}
|
|
61
63
|
if (req.query.theme) {
|
|
62
64
|
req.session.theme = req.query.theme;
|
|
63
|
-
const redirectUrl = req.path ||
|
|
65
|
+
const redirectUrl = req.path || '/';
|
|
64
66
|
if (!req.query.market && !req.query.devMode) {
|
|
65
67
|
return res.redirect(redirectUrl);
|
|
66
68
|
}
|
|
@@ -68,7 +70,7 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
68
70
|
else if (themeId) {
|
|
69
71
|
req.session.theme = themeId;
|
|
70
72
|
}
|
|
71
|
-
(0, locals_1.setLocales)(
|
|
73
|
+
(0, locals_1.setLocales)('cookies', req.cookies);
|
|
72
74
|
next();
|
|
73
75
|
});
|
|
74
76
|
app.use((0, init_middleware_1.initMiddleware)({
|
|
@@ -80,24 +82,28 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
80
82
|
market,
|
|
81
83
|
}));
|
|
82
84
|
const availablePort = await (0, findAvailablePort_1.findAvailablePort)(port);
|
|
83
|
-
if (mode ===
|
|
84
|
-
const staticPath = path_1.default.join(process.cwd(),
|
|
85
|
-
app.use(
|
|
85
|
+
if (mode === 'devlopment') {
|
|
86
|
+
const staticPath = path_1.default.join(process.cwd(), 'assets');
|
|
87
|
+
app.use('/assets', express_1.default.static(staticPath));
|
|
86
88
|
// app.use("/api", devRouter);
|
|
87
89
|
}
|
|
90
|
+
const notFoundPagePath = path_2.default.join(__dirname, 'pages', '404.html');
|
|
91
|
+
const notFoundPage = fs_1.default.readFileSync(notFoundPagePath, 'utf8');
|
|
88
92
|
app.use((req, res, next) => {
|
|
89
93
|
const path = res.locals.parsedUrl?.pathname || req.path;
|
|
90
94
|
const result = (0, isPathAllowedToRender_1.validatePathForRender)(path);
|
|
91
95
|
if (!result.allowed) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
console.log("🚀 ~ startEngine ~ notFoundPagePath:", notFoundPagePath);
|
|
97
|
+
// return res.status(result.status).json({
|
|
98
|
+
// success: false,
|
|
99
|
+
// message: result.reason,
|
|
100
|
+
// });
|
|
101
|
+
return res.status(result.status).send(notFoundPage);
|
|
96
102
|
}
|
|
97
103
|
next();
|
|
98
104
|
});
|
|
99
105
|
app.use((_, res, next) => {
|
|
100
|
-
res.locals.themesRepo = path_1.default.join(process.cwd(), themesRepo ||
|
|
106
|
+
res.locals.themesRepo = path_1.default.join(process.cwd(), themesRepo || '');
|
|
101
107
|
next();
|
|
102
108
|
});
|
|
103
109
|
app.use(production_1.default);
|
|
@@ -112,13 +118,13 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
112
118
|
app.listen(availablePort, () => {
|
|
113
119
|
(0, printServerLog_1.printServerLog)({
|
|
114
120
|
port: availablePort,
|
|
115
|
-
themeId: themeId ||
|
|
121
|
+
themeId: themeId || 'default',
|
|
116
122
|
app: currentApp,
|
|
117
123
|
});
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
126
|
catch (err) {
|
|
121
|
-
console.error(
|
|
127
|
+
console.error('❌ Server failed to start:', err);
|
|
122
128
|
}
|
|
123
129
|
};
|
|
124
130
|
exports.default = startEngine;
|