qumra-engine 2.0.163 → 2.0.165
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 +26 -23
- package/dist/pages/404.d.ts +1 -0
- package/dist/pages/404.js +75 -0
- 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,33 @@ 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 _404_1 = require("./pages/404");
|
|
26
|
+
const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000, themesRepo, themeId = null, currentApp, market }) => {
|
|
26
27
|
try {
|
|
27
28
|
const app = (0, express_1.default)();
|
|
28
|
-
const isProduction = process.env.NODE_ENV ===
|
|
29
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
29
30
|
app.use((0, cookie_parser_1.default)());
|
|
30
31
|
app.use(express_1.default.urlencoded({ extended: true }));
|
|
31
32
|
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(
|
|
33
|
+
app.use((0, morgan_1.default)('dev'));
|
|
34
|
+
app.set('view engine', 'nunjucks');
|
|
35
|
+
app.set('trust proxy', 1);
|
|
36
|
+
app.get('/health', (_, res) => {
|
|
37
|
+
console.log('🚀 Health check OK');
|
|
38
|
+
return res.status(200).send('OK');
|
|
38
39
|
});
|
|
39
40
|
app.use((req, res, next) => {
|
|
40
41
|
res.locals.showDevTools = req.query.showDevTools ?? false;
|
|
41
|
-
const isIframe = req.query.iframe ===
|
|
42
|
+
const isIframe = req.query.iframe === '1' || req.headers['sec-fetch-dest'] === 'iframe';
|
|
42
43
|
res.locals.isIframe = !!isIframe;
|
|
43
44
|
next();
|
|
44
45
|
});
|
|
45
46
|
app.use((0, express_session_1.default)({
|
|
46
|
-
secret: process.env.SESSION_SECRET ||
|
|
47
|
+
secret: process.env.SESSION_SECRET || 'your-secret-key',
|
|
47
48
|
resave: false,
|
|
48
49
|
saveUninitialized: false,
|
|
49
50
|
cookie: {
|
|
50
|
-
sameSite:
|
|
51
|
+
sameSite: 'none',
|
|
51
52
|
secure: isProduction,
|
|
52
53
|
httpOnly: true,
|
|
53
54
|
partitioned: true,
|
|
@@ -60,7 +61,7 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
60
61
|
}
|
|
61
62
|
if (req.query.theme) {
|
|
62
63
|
req.session.theme = req.query.theme;
|
|
63
|
-
const redirectUrl = req.path ||
|
|
64
|
+
const redirectUrl = req.path || '/';
|
|
64
65
|
if (!req.query.market && !req.query.devMode) {
|
|
65
66
|
return res.redirect(redirectUrl);
|
|
66
67
|
}
|
|
@@ -68,7 +69,7 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
68
69
|
else if (themeId) {
|
|
69
70
|
req.session.theme = themeId;
|
|
70
71
|
}
|
|
71
|
-
(0, locals_1.setLocales)(
|
|
72
|
+
(0, locals_1.setLocales)('cookies', req.cookies);
|
|
72
73
|
next();
|
|
73
74
|
});
|
|
74
75
|
app.use((0, init_middleware_1.initMiddleware)({
|
|
@@ -80,24 +81,26 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
80
81
|
market,
|
|
81
82
|
}));
|
|
82
83
|
const availablePort = await (0, findAvailablePort_1.findAvailablePort)(port);
|
|
83
|
-
if (mode ===
|
|
84
|
-
const staticPath = path_1.default.join(process.cwd(),
|
|
85
|
-
app.use(
|
|
84
|
+
if (mode === 'devlopment') {
|
|
85
|
+
const staticPath = path_1.default.join(process.cwd(), 'assets');
|
|
86
|
+
app.use('/assets', express_1.default.static(staticPath));
|
|
86
87
|
// app.use("/api", devRouter);
|
|
87
88
|
}
|
|
88
89
|
app.use((req, res, next) => {
|
|
89
90
|
const path = res.locals.parsedUrl?.pathname || req.path;
|
|
90
91
|
const result = (0, isPathAllowedToRender_1.validatePathForRender)(path);
|
|
91
92
|
if (!result.allowed) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
console.log("🚀 ~ startEngine ~ notFoundPagePath:", _404_1.notFoundPage);
|
|
94
|
+
// return res.status(result.status).json({
|
|
95
|
+
// success: false,
|
|
96
|
+
// message: result.reason,
|
|
97
|
+
// });
|
|
98
|
+
return res.status(result.status).send(_404_1.notFoundPage);
|
|
96
99
|
}
|
|
97
100
|
next();
|
|
98
101
|
});
|
|
99
102
|
app.use((_, res, next) => {
|
|
100
|
-
res.locals.themesRepo = path_1.default.join(process.cwd(), themesRepo ||
|
|
103
|
+
res.locals.themesRepo = path_1.default.join(process.cwd(), themesRepo || '');
|
|
101
104
|
next();
|
|
102
105
|
});
|
|
103
106
|
app.use(production_1.default);
|
|
@@ -112,13 +115,13 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
|
|
|
112
115
|
app.listen(availablePort, () => {
|
|
113
116
|
(0, printServerLog_1.printServerLog)({
|
|
114
117
|
port: availablePort,
|
|
115
|
-
themeId: themeId ||
|
|
118
|
+
themeId: themeId || 'default',
|
|
116
119
|
app: currentApp,
|
|
117
120
|
});
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
123
|
catch (err) {
|
|
121
|
-
console.error(
|
|
124
|
+
console.error('❌ Server failed to start:', err);
|
|
122
125
|
}
|
|
123
126
|
};
|
|
124
127
|
exports.default = startEngine;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const notFoundPage = "\n<!DOCTYPE html>\n<html lang=\"ar\" dir=\"rtl\">\n<head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>\u0627\u0644\u0635\u0641\u062D\u0629 \u063A\u064A\u0631 \u0645\u0648\u062C\u0648\u062F\u0629</title>\n <style>\n body {\n margin: 0;\n padding: 0;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto;\n background: #f9fafb;\n color: #111827;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n text-align: center;\n }\n\n .container {\n max-width: 420px;\n padding: 20px;\n }\n\n h1 {\n font-size: 82px;\n margin-bottom: 0;\n color: #ef4444;\n font-weight: 800;\n }\n\n .subtitle {\n font-size: 22px;\n margin-bottom: 15px;\n }\n\n p {\n font-size: 16px;\n color: #6b7280;\n margin-bottom: 30px;\n }\n\n a {\n display: inline-block;\n padding: 12px 26px;\n background: #111827;\n color: #fff;\n border-radius: 10px;\n text-decoration: none;\n font-size: 16px;\n transition: 0.2s;\n }\n\n a:hover {\n background: #000;\n transform: translateY(-2px);\n }\n </style>\n</head>\n\n<body>\n <div class=\"container\">\n <h1>404</h1>\n <div class=\"subtitle\">\u0627\u0644\u0635\u0641\u062D\u0629 \u063A\u064A\u0631 \u0645\u0648\u062C\u0648\u062F\u0629</div>\n <p>\u0627\u0644\u0635\u0641\u062D\u0629 \u0627\u0644\u062A\u064A \u062A\u062D\u0627\u0648\u0644 \u0627\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u064A\u0647\u0627 \u063A\u064A\u0631 \u0645\u062A\u0627\u062D\u0629 \u0623\u0648 \u062A\u0645 \u0646\u0642\u0644\u0647\u0627.</p>\n <a href=\"/\">\u0627\u0644\u0631\u062C\u0648\u0639 \u0644\u0644\u0631\u0626\u064A\u0633\u064A\u0629</a>\n </div>\n</body>\n</html>\n";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notFoundPage = void 0;
|
|
4
|
+
exports.notFoundPage = `
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="ar" dir="rtl">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="UTF-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
10
|
+
<title>الصفحة غير موجودة</title>
|
|
11
|
+
<style>
|
|
12
|
+
body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 0;
|
|
15
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;
|
|
16
|
+
background: #f9fafb;
|
|
17
|
+
color: #111827;
|
|
18
|
+
display: flex;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
height: 100vh;
|
|
22
|
+
text-align: center;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.container {
|
|
26
|
+
max-width: 420px;
|
|
27
|
+
padding: 20px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
h1 {
|
|
31
|
+
font-size: 82px;
|
|
32
|
+
margin-bottom: 0;
|
|
33
|
+
color: #ef4444;
|
|
34
|
+
font-weight: 800;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.subtitle {
|
|
38
|
+
font-size: 22px;
|
|
39
|
+
margin-bottom: 15px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
p {
|
|
43
|
+
font-size: 16px;
|
|
44
|
+
color: #6b7280;
|
|
45
|
+
margin-bottom: 30px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
a {
|
|
49
|
+
display: inline-block;
|
|
50
|
+
padding: 12px 26px;
|
|
51
|
+
background: #111827;
|
|
52
|
+
color: #fff;
|
|
53
|
+
border-radius: 10px;
|
|
54
|
+
text-decoration: none;
|
|
55
|
+
font-size: 16px;
|
|
56
|
+
transition: 0.2s;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
a:hover {
|
|
60
|
+
background: #000;
|
|
61
|
+
transform: translateY(-2px);
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
</head>
|
|
65
|
+
|
|
66
|
+
<body>
|
|
67
|
+
<div class="container">
|
|
68
|
+
<h1>404</h1>
|
|
69
|
+
<div class="subtitle">الصفحة غير موجودة</div>
|
|
70
|
+
<p>الصفحة التي تحاول الوصول إليها غير متاحة أو تم نقلها.</p>
|
|
71
|
+
<a href="/">الرجوع للرئيسية</a>
|
|
72
|
+
</div>
|
|
73
|
+
</body>
|
|
74
|
+
</html>
|
|
75
|
+
`;
|