create-jwn-js 1.2.1 → 1.2.2
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/package.json +1 -1
- package/template-vite-vue3-mts/src/scripts/vitest.global.setup.mts +3 -3
- package/template-vite-vue3-pinia-mts/dist/client/.vite/ssr-manifest.json +1169 -69
- package/template-vite-vue3-pinia-mts/dist/client/assets/index-B40M1W6I.css +1 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/index-CrrygVvU.js +249 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/primeicons-C6QP2o4f.woff2 +0 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/primeicons-DMOk5skT.eot +0 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/primeicons-Dr5RGzOO.svg +345 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/primeicons-MpK4pl85.ttf +0 -0
- package/template-vite-vue3-pinia-mts/dist/client/assets/primeicons-WjwUDZjB.woff +0 -0
- package/template-vite-vue3-pinia-mts/dist/client/robots.txt +2 -0
- package/template-vite-vue3-pinia-mts/dist/server/entry-server.mjs +239 -354
- package/template-vite-vue3-pinia-mts/dist/server/package.json +2 -1
- package/template-vite-vue3-pinia-mts/dist/server/robots.txt +2 -0
- package/template-vite-vue3-pinia-mts/package.json +4 -4
- package/template-vite-vue3-pinia-mts/yarn.lock +260 -323
- package/template-vite-vue3-pinia-mts/dist/client/assets/index-B8XEaJMM.css +0 -1
- package/template-vite-vue3-pinia-mts/dist/client/assets/index-DJNddzdM.js +0 -224
|
@@ -3,20 +3,20 @@ import { renderToString } from "@vue/server-renderer";
|
|
|
3
3
|
import { renderHeadToString, createHead, useHead } from "@vueuse/head";
|
|
4
4
|
import { parse } from "node-html-parser";
|
|
5
5
|
import { createRouter as createRouter$1, createWebHistory, createMemoryHistory } from "vue-router";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { isBrowser } from "easy-ash";
|
|
9
|
-
import fetch from "cross-fetch";
|
|
6
|
+
import { defineStore, storeToRefs, createPinia } from "pinia";
|
|
7
|
+
import { isBrowser, omit } from "easy-ash";
|
|
10
8
|
import { ApiError } from "@jwn-js/common/ApiError.mjs";
|
|
9
|
+
import { ssrRenderAttrs, ssrInterpolate, ssrRenderComponent } from "vue/server-renderer";
|
|
11
10
|
import { createPrefetch } from "@vuemod/prefetch";
|
|
12
11
|
import { amitt } from "amitt";
|
|
13
12
|
import Multilang from "@jwn-js/plugins/Multilang/index.js";
|
|
14
13
|
import PrimeVue from "primevue/config";
|
|
14
|
+
import Aura from "@primevue/themes/aura";
|
|
15
15
|
import ConfirmationService from "primevue/confirmationservice";
|
|
16
|
-
import
|
|
16
|
+
import ToastService from "primevue/toastservice";
|
|
17
|
+
import { helpers, Server, Web, Ssr } from "@jwn-js/common";
|
|
17
18
|
import margv from "margv";
|
|
18
19
|
import { Query } from "buildmsql";
|
|
19
|
-
import memjs from "memjs";
|
|
20
20
|
import JSON5 from "json5";
|
|
21
21
|
import path from "node:path";
|
|
22
22
|
import fs from "node:fs";
|
|
@@ -149,7 +149,7 @@ const createViteSsrVue = (App2, options2 = {}) => {
|
|
|
149
149
|
initialState: {},
|
|
150
150
|
...extra
|
|
151
151
|
};
|
|
152
|
-
const { head, router, store, inserts, context } = options2.created && await options2.created({
|
|
152
|
+
const { head, router, store, inserts, context, pinia } = options2.created && await options2.created({
|
|
153
153
|
app,
|
|
154
154
|
...ssrContext
|
|
155
155
|
}) || {};
|
|
@@ -161,11 +161,15 @@ const createViteSsrVue = (App2, options2 = {}) => {
|
|
|
161
161
|
app,
|
|
162
162
|
router,
|
|
163
163
|
store,
|
|
164
|
+
pinia,
|
|
164
165
|
...ssrContext
|
|
165
166
|
});
|
|
166
167
|
if (store) {
|
|
167
168
|
ssrContext.initialState.state = store.state;
|
|
168
169
|
}
|
|
170
|
+
if (pinia) {
|
|
171
|
+
ssrContext.initialState.pinia = pinia.state.value;
|
|
172
|
+
}
|
|
169
173
|
const body = (inserts == null ? void 0 : inserts.body) || await renderToString(app, Object.assign(ssrContext, context || {}));
|
|
170
174
|
let headTags = (inserts == null ? void 0 : inserts.headTags) || "", htmlAttrs = (inserts == null ? void 0 : inserts.htmlAttrs) || "", bodyAttrs = (inserts == null ? void 0 : inserts.bodyAttrs) || "", dependencies = (inserts == null ? void 0 : inserts.dependencies) || [];
|
|
171
175
|
if (head) {
|
|
@@ -192,6 +196,7 @@ const createViteSsrVue = (App2, options2 = {}) => {
|
|
|
192
196
|
app,
|
|
193
197
|
router,
|
|
194
198
|
store,
|
|
199
|
+
pinia,
|
|
195
200
|
...ssrContext
|
|
196
201
|
});
|
|
197
202
|
const initialState = await serializer(ssrContext.initialState || {});
|
|
@@ -210,8 +215,8 @@ const createViteSsrVue = (App2, options2 = {}) => {
|
|
|
210
215
|
}
|
|
211
216
|
|
|
212
217
|
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4Lmh0bWwlM0ZodG1sLXByb3h5JmlubGluZS1jc3MmaW5kZXg9MC5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtZQUNZO2dCQUNJLFdBQVc7WUFDZiIsImZpbGUiOiJpbmRleC5odG1sP2h0bWwtcHJveHkmaW5saW5lLWNzcyZpbmRleD0wLmNzcyIsInNvdXJjZXNDb250ZW50IjpbIlxuICAgICAgICAgICAgLmljb25pbmcge1xuICAgICAgICAgICAgICAgIHdpZHRoOiAyMHB4O1xuICAgICAgICAgICAgfVxuICAgICAgICAiXX0= */</style>
|
|
213
|
-
<script type="module" crossorigin src="/assets/index-
|
|
214
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
218
|
+
<script type="module" crossorigin src="/assets/index-CrrygVvU.js"><\/script>
|
|
219
|
+
<link rel="stylesheet" crossorigin href="/assets/index-B40M1W6I.css">
|
|
215
220
|
${headTags}
|
|
216
221
|
</head>
|
|
217
222
|
<body${bodyAttrs}>
|
|
@@ -229,23 +234,156 @@ const createViteSsrVue = (App2, options2 = {}) => {
|
|
|
229
234
|
};
|
|
230
235
|
};
|
|
231
236
|
};
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
return target;
|
|
237
|
+
const langLink = (url, lang = "ru", defaultLang2 = "ru") => {
|
|
238
|
+
url = (url || "").replace(/\/(ru|ua|en)(\/|$)/, "/");
|
|
239
|
+
const result = (lang === defaultLang2 ? "" : "/" + lang) + url;
|
|
240
|
+
return result === "/" ? result : result.replace(/\/$/, "");
|
|
238
241
|
};
|
|
242
|
+
const useBaseStore = defineStore("baseStore", {
|
|
243
|
+
state: () => {
|
|
244
|
+
return {
|
|
245
|
+
context: {},
|
|
246
|
+
// Ssr context
|
|
247
|
+
page: {
|
|
248
|
+
h1: "",
|
|
249
|
+
title: "",
|
|
250
|
+
htmlAttrs: {}
|
|
251
|
+
},
|
|
252
|
+
way: [],
|
|
253
|
+
// breadcrumbs
|
|
254
|
+
microdata: "",
|
|
255
|
+
// Микроразметка
|
|
256
|
+
toLang: "ua",
|
|
257
|
+
// Before route - set to new value
|
|
258
|
+
lang: "ua",
|
|
259
|
+
// After route set to new value
|
|
260
|
+
loading: false
|
|
261
|
+
// is data loading
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
getters: {
|
|
265
|
+
getBaseUrl() {
|
|
266
|
+
return `${this.context.protocol}://${this.context.hostname}`;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
actions: {
|
|
270
|
+
mergeContext(context) {
|
|
271
|
+
Object.assign(this.context, context);
|
|
272
|
+
},
|
|
273
|
+
addToastNotify(params) {
|
|
274
|
+
this.$emitter.emit("web-notification", params);
|
|
275
|
+
},
|
|
276
|
+
langLink(path2) {
|
|
277
|
+
return langLink(path2, this.lang);
|
|
278
|
+
},
|
|
279
|
+
async fetch(input, init = {}, opts = {}) {
|
|
280
|
+
var _a, _b;
|
|
281
|
+
const url = new URL(`${this.getBaseUrl}${input}`);
|
|
282
|
+
const token = (init == null ? void 0 : init.token) || "";
|
|
283
|
+
const search = url.searchParams;
|
|
284
|
+
search.set("lang", search.get("lang") || this.lang);
|
|
285
|
+
const ssrHeaders = this.context.headers || {};
|
|
286
|
+
if (isBrowser()) {
|
|
287
|
+
[
|
|
288
|
+
"host",
|
|
289
|
+
"connection",
|
|
290
|
+
"user-agent",
|
|
291
|
+
"referer",
|
|
292
|
+
"accept-encoding",
|
|
293
|
+
"cookie",
|
|
294
|
+
"sec-ch-ua",
|
|
295
|
+
"sec-ch-ua-mobile",
|
|
296
|
+
"sec-fetch-site",
|
|
297
|
+
"sec-fetch-mode",
|
|
298
|
+
"sec-fetch-dest",
|
|
299
|
+
"sec-fetch-user",
|
|
300
|
+
"sec-ch-ua-platform"
|
|
301
|
+
].map((key) => delete ssrHeaders[key]);
|
|
302
|
+
} else {
|
|
303
|
+
ssrHeaders["x-forwarded-for"] = this.context.ip;
|
|
304
|
+
}
|
|
305
|
+
init.headers = init.headers || {};
|
|
306
|
+
init.headers = Object.assign(
|
|
307
|
+
{},
|
|
308
|
+
ssrHeaders,
|
|
309
|
+
(init == null ? void 0 : init.body) instanceof FormData ? {} : { "content-type": "application/json" },
|
|
310
|
+
token ? { "authorization": "Bearer " + token } : {},
|
|
311
|
+
init.headers
|
|
312
|
+
);
|
|
313
|
+
init.method = init.method || "GET";
|
|
314
|
+
if (["get", "head"].includes(init.method.toLowerCase())) {
|
|
315
|
+
url.search = new URLSearchParams((init == null ? void 0 : init.data) || url.search || {}).toString();
|
|
316
|
+
} else {
|
|
317
|
+
init.body = (init == null ? void 0 : init.body) || JSON.stringify((init == null ? void 0 : init.data) || {});
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
this.loading = true;
|
|
321
|
+
const response = await fetch(url, init);
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const headers = {};
|
|
324
|
+
response.headers.forEach((value, key) => headers[key] = value);
|
|
325
|
+
const text = await response.text();
|
|
326
|
+
let json = {};
|
|
327
|
+
try {
|
|
328
|
+
json = JSON.parse(text);
|
|
329
|
+
} catch (e) {
|
|
330
|
+
}
|
|
331
|
+
throw new ApiError({
|
|
332
|
+
code: json.code || 0,
|
|
333
|
+
statusCode: response.status,
|
|
334
|
+
message: "Web api request error",
|
|
335
|
+
headers,
|
|
336
|
+
data: { json, text }
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return response;
|
|
340
|
+
} catch (e) {
|
|
341
|
+
if (e instanceof TypeError) {
|
|
342
|
+
if (isBrowser()) {
|
|
343
|
+
this.addToastNotify({
|
|
344
|
+
severity: "error",
|
|
345
|
+
detail: "Check your internet connection. No contact)"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (e instanceof ApiError) {
|
|
350
|
+
const statusCode = e.getStatusCode();
|
|
351
|
+
const error = ((_b = (_a = e.getData()) == null ? void 0 : _a.json) == null ? void 0 : _b.error) || e.getData().text || e.getMessage();
|
|
352
|
+
if (init.method.toLowerCase() === "get") {
|
|
353
|
+
if (statusCode === 410) {
|
|
354
|
+
const location = e.getHeaders().location;
|
|
355
|
+
if (location) {
|
|
356
|
+
await this.$redirect(location);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (statusCode >= 400 && !opts.suppressError && statusCode !== 410) {
|
|
361
|
+
isBrowser() ? this.addToastNotify({ severity: "error", summary: "Request error", detail: error }) : this.$redirect(langLink(`/${statusCode}?error=${encodeURIComponent(error)}`, this.lang));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
throw e;
|
|
365
|
+
} finally {
|
|
366
|
+
this.loading = false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
239
371
|
const _sfc_main$2 = defineComponent({
|
|
240
372
|
name: "Error",
|
|
241
373
|
async prefetch({ store, isClient }, to, from) {
|
|
242
|
-
store
|
|
374
|
+
const baseStore = useBaseStore(store);
|
|
375
|
+
baseStore.page = {
|
|
243
376
|
title: "Error page. Something went wrong",
|
|
244
377
|
htmlAttrs: {
|
|
245
378
|
lang: "en"
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
379
|
+
},
|
|
380
|
+
h1: ""
|
|
381
|
+
};
|
|
382
|
+
baseStore.mergeContext({ statusCode: 404 });
|
|
383
|
+
},
|
|
384
|
+
setup() {
|
|
385
|
+
const baseStore = useBaseStore();
|
|
386
|
+
return { baseStore };
|
|
249
387
|
},
|
|
250
388
|
props: {
|
|
251
389
|
code: {
|
|
@@ -254,14 +392,19 @@ const _sfc_main$2 = defineComponent({
|
|
|
254
392
|
}
|
|
255
393
|
},
|
|
256
394
|
created() {
|
|
257
|
-
this.mergeContext({ statusCode: this.code });
|
|
395
|
+
this.baseStore.mergeContext({ statusCode: parseInt(this.code) });
|
|
258
396
|
},
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
mergeContext: "MERGE_CONTEXT"
|
|
262
|
-
})
|
|
397
|
+
mounted() {
|
|
398
|
+
console.log("Component mounted.");
|
|
263
399
|
}
|
|
264
400
|
});
|
|
401
|
+
const _export_sfc = (sfc, props) => {
|
|
402
|
+
const target = sfc.__vccOpts || sfc;
|
|
403
|
+
for (const [key, val] of props) {
|
|
404
|
+
target[key] = val;
|
|
405
|
+
}
|
|
406
|
+
return target;
|
|
407
|
+
};
|
|
265
408
|
function _sfc_ssrRender$2(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
|
|
266
409
|
const _component_RouterLink = resolveComponent("RouterLink");
|
|
267
410
|
_push(`<div${ssrRenderAttrs(mergeProps({ class: "error-page" }, _attrs))}><div class="code">${ssrInterpolate(_ctx.code)}</div><div class="content">Oops. Something went wrong</div>`);
|
|
@@ -290,30 +433,38 @@ _sfc_main$2.setup = (props, ctx) => {
|
|
|
290
433
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("src/frontend/views/Error/Error.vue");
|
|
291
434
|
return _sfc_setup$2 ? _sfc_setup$2(props, ctx) : void 0;
|
|
292
435
|
};
|
|
293
|
-
const Error$1 = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["ssrRender", _sfc_ssrRender$2], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-mts/src/frontend/views/Error/Error.vue"]]);
|
|
294
|
-
const
|
|
436
|
+
const Error$1 = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["ssrRender", _sfc_ssrRender$2], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-pinia-mts/src/frontend/views/Error/Error.vue"]]);
|
|
437
|
+
const customerPrefetchPinia = (options2, fn) => {
|
|
295
438
|
return async ({ store, isFetch }, to, from) => {
|
|
296
|
-
var _a, _b
|
|
439
|
+
var _a, _b;
|
|
297
440
|
if (isFetch) {
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
441
|
+
const baseStore = useBaseStore(store);
|
|
442
|
+
const res = await baseStore.fetch("/web", {
|
|
443
|
+
data: {
|
|
444
|
+
lang: baseStore.toLang,
|
|
445
|
+
route: to.fullPath,
|
|
446
|
+
...to.query || {},
|
|
447
|
+
...options2 || {}
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
const body = await res.json();
|
|
451
|
+
const page = (_a = body.data) == null ? void 0 : _a.page;
|
|
452
|
+
baseStore.page = page ? omit(page, ["way"]) : {};
|
|
453
|
+
baseStore.way = (page == null ? void 0 : page.way) || [];
|
|
454
|
+
baseStore.microdata = ((_b = body.data) == null ? void 0 : _b.microdata) || "";
|
|
455
|
+
baseStore.mergeContext({ memcache: options2.memcache || null });
|
|
308
456
|
}
|
|
309
457
|
};
|
|
310
458
|
};
|
|
311
459
|
const _sfc_main$1 = defineComponent({
|
|
312
460
|
name: "Index",
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
461
|
+
prefetch: customerPrefetchPinia({ controller: "Index" }),
|
|
462
|
+
setup() {
|
|
463
|
+
const baseStore = useBaseStore();
|
|
464
|
+
const { page } = storeToRefs(baseStore);
|
|
465
|
+
return {
|
|
466
|
+
page
|
|
467
|
+
};
|
|
317
468
|
}
|
|
318
469
|
});
|
|
319
470
|
function _sfc_ssrRender$1(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
|
|
@@ -325,7 +476,7 @@ _sfc_main$1.setup = (props, ctx) => {
|
|
|
325
476
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("src/frontend/views/Index/Index.vue");
|
|
326
477
|
return _sfc_setup$1 ? _sfc_setup$1(props, ctx) : void 0;
|
|
327
478
|
};
|
|
328
|
-
const Index = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["ssrRender", _sfc_ssrRender$1], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-mts/src/frontend/views/Index/Index.vue"]]);
|
|
479
|
+
const Index = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["ssrRender", _sfc_ssrRender$1], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-pinia-mts/src/frontend/views/Index/Index.vue"]]);
|
|
329
480
|
const createRouter = (opt) => createRouter$1({
|
|
330
481
|
history: opt.isClient ? createWebHistory() : createMemoryHistory(),
|
|
331
482
|
routes: [
|
|
@@ -350,281 +501,13 @@ const createRouter = (opt) => createRouter$1({
|
|
|
350
501
|
var _a;
|
|
351
502
|
if ((_a = to.query) == null ? void 0 : _a.el) {
|
|
352
503
|
const el = to.query.el;
|
|
353
|
-
return {
|
|
354
|
-
el
|
|
355
|
-
};
|
|
504
|
+
return { el };
|
|
356
505
|
}
|
|
357
506
|
if (to.meta.scrollToTop) {
|
|
358
507
|
return { left: 0, top: 0 };
|
|
359
508
|
}
|
|
360
509
|
}
|
|
361
510
|
});
|
|
362
|
-
const langLink = (url, lang = "ru", defaultLang2 = "ru") => {
|
|
363
|
-
url = (url || "").replace(/\/(ru|ua|en)(\/|$)/, "/");
|
|
364
|
-
const result = (lang === defaultLang2 ? "" : "/" + lang) + url;
|
|
365
|
-
return result === "/" ? result : result.replace(/\/$/, "");
|
|
366
|
-
};
|
|
367
|
-
const fetchAction = async ({ state, commit, getters, dispatch }, [
|
|
368
|
-
params = {},
|
|
369
|
-
options2
|
|
370
|
-
]) => {
|
|
371
|
-
var _a, _b, _c;
|
|
372
|
-
const headers = {};
|
|
373
|
-
try {
|
|
374
|
-
const isFormData = typeof FormData !== "undefined" && params instanceof FormData;
|
|
375
|
-
const ssrHeaders = state.context.headers || {};
|
|
376
|
-
if (isFormData) {
|
|
377
|
-
if (!params.has("lang")) {
|
|
378
|
-
params.append("lang", state.lang);
|
|
379
|
-
}
|
|
380
|
-
} else {
|
|
381
|
-
if (!params.lang) {
|
|
382
|
-
params.lang = state.lang;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
if (isBrowser()) {
|
|
386
|
-
[
|
|
387
|
-
"host",
|
|
388
|
-
"connection",
|
|
389
|
-
"user-agent",
|
|
390
|
-
"referer",
|
|
391
|
-
"accept-encoding",
|
|
392
|
-
"cookie",
|
|
393
|
-
"sec-ch-ua",
|
|
394
|
-
"sec-ch-ua-mobile",
|
|
395
|
-
"sec-fetch-site",
|
|
396
|
-
"sec-fetch-mode",
|
|
397
|
-
"sec-fetch-dest",
|
|
398
|
-
"sec-fetch-user",
|
|
399
|
-
"sec-ch-ua-platform"
|
|
400
|
-
].map((key) => delete ssrHeaders[key]);
|
|
401
|
-
} else {
|
|
402
|
-
ssrHeaders["x-forwarded-for"] = state.context.ip;
|
|
403
|
-
}
|
|
404
|
-
const defaultOptions = {
|
|
405
|
-
url: `${getters.getBaseUrl}/web`,
|
|
406
|
-
method: "get",
|
|
407
|
-
preloader: true,
|
|
408
|
-
error: true,
|
|
409
|
-
compress: true,
|
|
410
|
-
headers: {
|
|
411
|
-
// Proxy ssr headers to request
|
|
412
|
-
...ssrHeaders,
|
|
413
|
-
...isFormData ? {} : { "content-type": "application/json" }
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
options2 = Object.assign(
|
|
417
|
-
{},
|
|
418
|
-
defaultOptions,
|
|
419
|
-
options2 || {}
|
|
420
|
-
);
|
|
421
|
-
if (options2 == null ? void 0 : options2.preloader) {
|
|
422
|
-
commit("SET_LOADING", true);
|
|
423
|
-
}
|
|
424
|
-
if (options2.mergeHeaders) {
|
|
425
|
-
options2.headers = Object.assign(options2.headers || {}, options2.mergeHeaders);
|
|
426
|
-
delete options2.mergeHeaders;
|
|
427
|
-
}
|
|
428
|
-
const url = new URL(options2.url);
|
|
429
|
-
if (!["get", "head"].includes((_a = options2 == null ? void 0 : options2.method) == null ? void 0 : _a.toLowerCase())) {
|
|
430
|
-
if (isFormData) {
|
|
431
|
-
options2.body = params;
|
|
432
|
-
} else {
|
|
433
|
-
options2.body = JSON.stringify(params);
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
url.search = new URLSearchParams(params).toString();
|
|
437
|
-
}
|
|
438
|
-
const response = await fetch(url.toString(), options2);
|
|
439
|
-
response.headers.forEach((value, key) => headers[key] = value);
|
|
440
|
-
const json = await response.json();
|
|
441
|
-
if (!response.ok) {
|
|
442
|
-
throw new ApiError({
|
|
443
|
-
code: json.code || 0,
|
|
444
|
-
statusCode: response.status,
|
|
445
|
-
message: "Api request error",
|
|
446
|
-
headers,
|
|
447
|
-
data: json
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
return { body: json, response };
|
|
451
|
-
} catch (e) {
|
|
452
|
-
if (e instanceof TypeError) {
|
|
453
|
-
if (isBrowser()) {
|
|
454
|
-
commit("SET_NOTIFICATION", {
|
|
455
|
-
type: "danger",
|
|
456
|
-
text: "Check your internet connection. No contact)"
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
if (e instanceof ApiError) {
|
|
461
|
-
const statusCode = e.getStatusCode();
|
|
462
|
-
if (statusCode === 400 && (options2 == null ? void 0 : options2.error)) {
|
|
463
|
-
commit("SET_NOTIFICATION", { type: "danger", text: e.getData()["error"] });
|
|
464
|
-
}
|
|
465
|
-
if (statusCode === 404 && (options2 == null ? void 0 : options2.error)) {
|
|
466
|
-
if (isBrowser()) {
|
|
467
|
-
commit("SET_NOTIFICATION", {
|
|
468
|
-
type: "danger",
|
|
469
|
-
text: "Something went wrong. We are working hard to fix this)"
|
|
470
|
-
});
|
|
471
|
-
} else {
|
|
472
|
-
await dispatch("redirect", {
|
|
473
|
-
url: "/404",
|
|
474
|
-
code: 307
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
if (((_b = options2 == null ? void 0 : options2.method) == null ? void 0 : _b.toLowerCase()) === "get") {
|
|
479
|
-
if (statusCode === 410) {
|
|
480
|
-
const location = (_c = e.getHeaders()) == null ? void 0 : _c.location;
|
|
481
|
-
if (location) {
|
|
482
|
-
await dispatch("redirect", { url: location, code: 307 });
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
throw e;
|
|
488
|
-
} finally {
|
|
489
|
-
if (options2 == null ? void 0 : options2.preloader) {
|
|
490
|
-
commit("SET_LOADING", false);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
const createStore = (opt) => createStore$1({
|
|
495
|
-
state: () => {
|
|
496
|
-
return {
|
|
497
|
-
context: {},
|
|
498
|
-
page: {},
|
|
499
|
-
way: [],
|
|
500
|
-
toLang: "ru",
|
|
501
|
-
lang: "ru",
|
|
502
|
-
loading: false
|
|
503
|
-
};
|
|
504
|
-
},
|
|
505
|
-
mutations: {
|
|
506
|
-
MERGE_CONTEXT(state, context) {
|
|
507
|
-
Object.assign(state.context, context);
|
|
508
|
-
},
|
|
509
|
-
MERGE_CONTEXT_HEADERS(state, headers) {
|
|
510
|
-
state.context.responseHeaders = Object.assign(state.context.responseHeaders || {}, headers);
|
|
511
|
-
},
|
|
512
|
-
SET_PAGE(state, page) {
|
|
513
|
-
state.page = page || {};
|
|
514
|
-
},
|
|
515
|
-
SET_WAY(state, way) {
|
|
516
|
-
state.way = way || [];
|
|
517
|
-
},
|
|
518
|
-
SET_LANG(state, lang) {
|
|
519
|
-
state.lang = lang;
|
|
520
|
-
},
|
|
521
|
-
SET_TO_LANG(state, lang) {
|
|
522
|
-
state.toLang = lang;
|
|
523
|
-
},
|
|
524
|
-
SET_LOADING(state, loading) {
|
|
525
|
-
state.loading = loading;
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
getters: {
|
|
529
|
-
getToLang(state) {
|
|
530
|
-
return state.toLang;
|
|
531
|
-
},
|
|
532
|
-
getLang(state) {
|
|
533
|
-
return state.lang;
|
|
534
|
-
},
|
|
535
|
-
urlFromLang: (state) => (url = "/", lang = state.toLang) => langLink(url, lang),
|
|
536
|
-
/**
|
|
537
|
-
* Get absolute url for requests
|
|
538
|
-
* @param state
|
|
539
|
-
*/
|
|
540
|
-
getBaseUrl(state) {
|
|
541
|
-
return `${state.context.protocol}://${state.context.hostname}`;
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
actions: {
|
|
545
|
-
/**
|
|
546
|
-
* Base fetch data action
|
|
547
|
-
* @param state
|
|
548
|
-
* @param payload
|
|
549
|
-
* @returns
|
|
550
|
-
*/
|
|
551
|
-
async fetch(state, payload) {
|
|
552
|
-
return fetchAction(state, payload);
|
|
553
|
-
},
|
|
554
|
-
/**
|
|
555
|
-
* Redirect
|
|
556
|
-
* @param context
|
|
557
|
-
* @param url auto transform to multilang
|
|
558
|
-
* @param query query params
|
|
559
|
-
* @param code status code for server, when on the client is discarded
|
|
560
|
-
*/
|
|
561
|
-
async redirect({ state, getters }, { url, code, query }) {
|
|
562
|
-
if (query) {
|
|
563
|
-
url = url + new URLSearchParams(query).toString();
|
|
564
|
-
}
|
|
565
|
-
await opt.redirect(langLink(url, state.toLang), code || 307);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
/*!
|
|
570
|
-
/**
|
|
571
|
-
* vuex-router-sync v6.0.0-rc.1
|
|
572
|
-
* (c) 2021 Evan You
|
|
573
|
-
* @license MIT
|
|
574
|
-
*/
|
|
575
|
-
function sync(store, router, options2) {
|
|
576
|
-
const moduleName = {}.moduleName || "route";
|
|
577
|
-
store.registerModule(moduleName, {
|
|
578
|
-
namespaced: true,
|
|
579
|
-
state: cloneRoute(router.currentRoute.value),
|
|
580
|
-
mutations: {
|
|
581
|
-
ROUTE_CHANGED(_state, transition) {
|
|
582
|
-
store.state[moduleName] = cloneRoute(transition.to, transition.from);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
let isTimeTraveling = false;
|
|
587
|
-
let currentPath;
|
|
588
|
-
const storeUnwatch = store.watch((state) => state[moduleName], (route) => {
|
|
589
|
-
const { fullPath } = route;
|
|
590
|
-
if (fullPath === currentPath) {
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
if (currentPath != null) {
|
|
594
|
-
isTimeTraveling = true;
|
|
595
|
-
router.push(route);
|
|
596
|
-
}
|
|
597
|
-
currentPath = fullPath;
|
|
598
|
-
}, { flush: "sync" });
|
|
599
|
-
const afterEachUnHook = router.afterEach((to, from) => {
|
|
600
|
-
if (isTimeTraveling) {
|
|
601
|
-
isTimeTraveling = false;
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
currentPath = to.fullPath;
|
|
605
|
-
store.commit(moduleName + "/ROUTE_CHANGED", { to, from });
|
|
606
|
-
});
|
|
607
|
-
return function unsync() {
|
|
608
|
-
afterEachUnHook();
|
|
609
|
-
storeUnwatch();
|
|
610
|
-
store.unregisterModule(moduleName);
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
function cloneRoute(to, from) {
|
|
614
|
-
const clone = {
|
|
615
|
-
name: to.name,
|
|
616
|
-
path: to.path,
|
|
617
|
-
hash: to.hash,
|
|
618
|
-
query: to.query,
|
|
619
|
-
params: to.params,
|
|
620
|
-
fullPath: to.fullPath,
|
|
621
|
-
meta: to.meta
|
|
622
|
-
};
|
|
623
|
-
if (from) {
|
|
624
|
-
clone.from = cloneRoute(from);
|
|
625
|
-
}
|
|
626
|
-
return Object.freeze(clone);
|
|
627
|
-
}
|
|
628
511
|
const parseLang = (url, defaultLang2 = "ru") => {
|
|
629
512
|
const result = url.match(/^\/(ru|ua|en)\/?/i);
|
|
630
513
|
return result && result.length > 0 ? result[1] : defaultLang2;
|
|
@@ -635,48 +518,64 @@ const options = {
|
|
|
635
518
|
const emitter = amitt();
|
|
636
519
|
const head = createHead();
|
|
637
520
|
const router = createRouter({ isClient });
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
521
|
+
const pinia = createPinia();
|
|
522
|
+
const redirect = async function(url, statusCode = 307) {
|
|
523
|
+
console.log("Redirecting: " + url);
|
|
524
|
+
isClient ? await router.push(url) : res.redirect(url, statusCode);
|
|
525
|
+
};
|
|
526
|
+
pinia.use(function() {
|
|
527
|
+
return {
|
|
528
|
+
"$redirect": redirect,
|
|
529
|
+
"$emitter": emitter
|
|
530
|
+
};
|
|
647
531
|
});
|
|
648
532
|
app.use(router);
|
|
649
|
-
app.use(
|
|
533
|
+
app.use(pinia);
|
|
650
534
|
app.use(head);
|
|
651
535
|
app.use(Multilang, {
|
|
652
536
|
default: defaultLang,
|
|
653
|
-
getLang()
|
|
654
|
-
return store.state.lang;
|
|
655
|
-
}
|
|
537
|
+
getLang: () => useBaseStore(pinia).lang
|
|
656
538
|
});
|
|
657
|
-
sync(store, router);
|
|
658
539
|
const prefetch = createPrefetch();
|
|
659
|
-
app.use(prefetch, router,
|
|
660
|
-
app.use(PrimeVue
|
|
661
|
-
|
|
540
|
+
app.use(prefetch, router, pinia);
|
|
541
|
+
app.use(PrimeVue, {
|
|
542
|
+
theme: {
|
|
543
|
+
preset: Aura,
|
|
544
|
+
options: {
|
|
545
|
+
darkModeSelector: false
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
app.use(ConfirmationService);
|
|
550
|
+
app.use(ToastService);
|
|
662
551
|
app.config.globalProperties.$emitter = emitter;
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
552
|
+
app.config.globalProperties.$emitter = emitter;
|
|
553
|
+
app.config.globalProperties.$redirect = redirect;
|
|
554
|
+
!isClient && (useBaseStore(pinia).context = context);
|
|
666
555
|
router.beforeEach(async (to) => {
|
|
667
|
-
|
|
556
|
+
useBaseStore(pinia).toLang = parseLang(to.fullPath, defaultLang);
|
|
668
557
|
});
|
|
669
558
|
router.afterEach(async (to, from) => {
|
|
670
|
-
|
|
559
|
+
useBaseStore(pinia).lang = parseLang(to.fullPath, defaultLang);
|
|
671
560
|
});
|
|
672
|
-
return { head, router,
|
|
561
|
+
return { head, router, pinia };
|
|
562
|
+
},
|
|
563
|
+
// В случае кеширования нельзя кешировать весь контекст
|
|
564
|
+
rendered({ isClient, pinia }) {
|
|
565
|
+
if (!isClient) {
|
|
566
|
+
const baseStore = useBaseStore(pinia);
|
|
567
|
+
baseStore.context.cookies = {};
|
|
568
|
+
baseStore.context.headers = {};
|
|
569
|
+
baseStore.context.ip = "";
|
|
570
|
+
baseStore.context.memcache = null;
|
|
571
|
+
}
|
|
673
572
|
}
|
|
674
573
|
};
|
|
675
574
|
const _sfc_main = defineComponent({
|
|
676
575
|
name: "App",
|
|
677
576
|
setup() {
|
|
678
|
-
const
|
|
679
|
-
useHead(computed(() =>
|
|
577
|
+
const baseStore = useBaseStore();
|
|
578
|
+
useHead(computed(() => baseStore.page));
|
|
680
579
|
}
|
|
681
580
|
});
|
|
682
581
|
function _sfc_ssrRender(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
|
|
@@ -691,7 +590,7 @@ _sfc_main.setup = (props, ctx) => {
|
|
|
691
590
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("src/frontend/App.vue");
|
|
692
591
|
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
693
592
|
};
|
|
694
|
-
const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["ssrRender", _sfc_ssrRender], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-mts/src/frontend/App.vue"]]);
|
|
593
|
+
const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["ssrRender", _sfc_ssrRender], ["__file", "/Volumes/MacMiniAPFS/projects/packages/vite-node-template/template-vite-vue3-pinia-mts/src/frontend/App.vue"]]);
|
|
695
594
|
const args = margv();
|
|
696
595
|
const createConfigServer = (config2, nodeEnv) => {
|
|
697
596
|
const env = process.env.NODE_ENV || "development";
|
|
@@ -739,18 +638,6 @@ const createMariadb = (config2) => {
|
|
|
739
638
|
}
|
|
740
639
|
return {};
|
|
741
640
|
};
|
|
742
|
-
const createMemcached = () => {
|
|
743
|
-
const memcachedClient2 = memjs.Client.create("127.0.0.1:11211", {
|
|
744
|
-
timeout: 1,
|
|
745
|
-
conntimeout: 1,
|
|
746
|
-
logger: {
|
|
747
|
-
log: () => {
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
const memcached2 = new Memcached(memcachedClient2);
|
|
752
|
-
return { memcachedClient: memcachedClient2, memcached: memcached2 };
|
|
753
|
-
};
|
|
754
641
|
const readManifest = () => {
|
|
755
642
|
let manifest = {};
|
|
756
643
|
try {
|
|
@@ -766,13 +653,13 @@ const readJson5ConfigsSync = (configs, input = {}) => {
|
|
|
766
653
|
}
|
|
767
654
|
return input;
|
|
768
655
|
};
|
|
656
|
+
const { readConfigSync } = helpers;
|
|
769
657
|
process.server = process.server || {};
|
|
770
|
-
let
|
|
658
|
+
let home;
|
|
771
659
|
const config = readJson5ConfigsSync(["./connect.json5", "./common.json5"]);
|
|
772
660
|
const configServer = createConfigServer(config);
|
|
773
661
|
if (process.env.NODE_ENV === "production") {
|
|
774
662
|
({ home } = createMariadb(config));
|
|
775
|
-
({ memcachedClient, memcached } = createMemcached());
|
|
776
663
|
}
|
|
777
664
|
const webOptions = {
|
|
778
665
|
routes: webRoutes,
|
|
@@ -780,12 +667,10 @@ const webOptions = {
|
|
|
780
667
|
db: process.server.db || {
|
|
781
668
|
home
|
|
782
669
|
},
|
|
783
|
-
memcached: process.server.memcached || memcached,
|
|
784
670
|
schema
|
|
785
671
|
};
|
|
786
672
|
const ssrOptions = {
|
|
787
|
-
manifest: readManifest()
|
|
788
|
-
memcached: process.server.memcached || memcached
|
|
673
|
+
manifest: readManifest()
|
|
789
674
|
};
|
|
790
675
|
process.server.app = new Server({
|
|
791
676
|
...configServer,
|