@nara-web/inertia-vue 1.0.1 → 1.0.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/dist/index.cjs +9 -5
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,8 +38,8 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
|
|
39
39
|
// src/middleware.ts
|
|
40
40
|
function inertiaMiddleware(options = {}) {
|
|
41
|
-
const { rootView = "inertia.html", version = "1.0.0" } = options;
|
|
42
|
-
return
|
|
41
|
+
const { rootView = "inertia.html", version = "1.0.0", viewFn = null } = options;
|
|
42
|
+
return (req, res, next) => {
|
|
43
43
|
res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
|
|
44
44
|
const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
|
|
45
45
|
const props = {
|
|
@@ -59,11 +59,15 @@ function inertiaMiddleware(options = {}) {
|
|
|
59
59
|
};
|
|
60
60
|
if (!req.header("X-Inertia")) {
|
|
61
61
|
try {
|
|
62
|
-
|
|
63
|
-
if (!
|
|
62
|
+
let viewFunc = viewFn;
|
|
63
|
+
if (!viewFunc) {
|
|
64
|
+
const viewService = await import("@services/View").catch(() => null);
|
|
65
|
+
viewFunc = viewService?.view;
|
|
66
|
+
}
|
|
67
|
+
if (!viewFunc) {
|
|
64
68
|
throw new Error("View service unavailable");
|
|
65
69
|
}
|
|
66
|
-
const html = await
|
|
70
|
+
const html = await viewFunc(rootView, {
|
|
67
71
|
page: JSON.stringify(inertiaObject),
|
|
68
72
|
title: process.env["TITLE"] || "Nara App"
|
|
69
73
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -41,6 +41,11 @@ interface VueAdapterOptions {
|
|
|
41
41
|
* @default '1.0.0'
|
|
42
42
|
*/
|
|
43
43
|
version?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional view function to render templates
|
|
46
|
+
* If not provided, will try to import from @services/View
|
|
47
|
+
*/
|
|
48
|
+
viewFn?: (filename: string, data?: any) => string | Promise<string>;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ interface VueAdapterOptions {
|
|
|
41
41
|
* @default '1.0.0'
|
|
42
42
|
*/
|
|
43
43
|
version?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional view function to render templates
|
|
46
|
+
* If not provided, will try to import from @services/View
|
|
47
|
+
*/
|
|
48
|
+
viewFn?: (filename: string, data?: any) => string | Promise<string>;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/middleware.ts
|
|
6
6
|
function inertiaMiddleware(options = {}) {
|
|
7
|
-
const { rootView = "inertia.html", version = "1.0.0" } = options;
|
|
8
|
-
return
|
|
7
|
+
const { rootView = "inertia.html", version = "1.0.0", viewFn = null } = options;
|
|
8
|
+
return (req, res, next) => {
|
|
9
9
|
res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
|
|
10
10
|
const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
|
|
11
11
|
const props = {
|
|
@@ -25,11 +25,15 @@ function inertiaMiddleware(options = {}) {
|
|
|
25
25
|
};
|
|
26
26
|
if (!req.header("X-Inertia")) {
|
|
27
27
|
try {
|
|
28
|
-
|
|
29
|
-
if (!
|
|
28
|
+
let viewFunc = viewFn;
|
|
29
|
+
if (!viewFunc) {
|
|
30
|
+
const viewService = await import("@services/View").catch(() => null);
|
|
31
|
+
viewFunc = viewService?.view;
|
|
32
|
+
}
|
|
33
|
+
if (!viewFunc) {
|
|
30
34
|
throw new Error("View service unavailable");
|
|
31
35
|
}
|
|
32
|
-
const html = await
|
|
36
|
+
const html = await viewFunc(rootView, {
|
|
33
37
|
page: JSON.stringify(inertiaObject),
|
|
34
38
|
title: process.env["TITLE"] || "Nara App"
|
|
35
39
|
});
|