@olenbetong/appframe-vite 1.0.2 → 1.0.5
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/lib/devServer.d.ts +2 -2
- package/lib/devServer.js +15 -14
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/package.json +1 -1
package/lib/devServer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Application, RequestHandler, Router } from "express";
|
|
2
2
|
import { ViteDevServer } from "vite";
|
|
3
3
|
export declare function createProxyMiddleware(): Promise<Router>;
|
|
4
|
-
export declare function createHtmlTransformer():
|
|
5
|
-
export declare function createDevMiddleware(vite: ViteDevServer):
|
|
4
|
+
export declare function createHtmlTransformer(): (html: string) => Promise<string>;
|
|
5
|
+
export declare function createDevMiddleware(vite: ViteDevServer): RequestHandler;
|
|
6
6
|
export declare function startDevServer(app: Application): Promise<void>;
|
package/lib/devServer.js
CHANGED
|
@@ -11,10 +11,16 @@ dotenv.config();
|
|
|
11
11
|
let appPkg = await importJson("./package.json", true);
|
|
12
12
|
let { appframe } = appPkg;
|
|
13
13
|
let userSession = null;
|
|
14
|
-
async function getUserSession(
|
|
14
|
+
async function getUserSession() {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
15
16
|
if (userSession) {
|
|
16
17
|
return userSession;
|
|
17
18
|
}
|
|
19
|
+
const hostname = (_d = (_b = (_a = appframe.proxy) === null || _a === void 0 ? void 0 : _a.hostname) !== null && _b !== void 0 ? _b : (_c = appframe.deploy) === null || _c === void 0 ? void 0 : _c.hostname) !== null && _d !== void 0 ? _d : "dev.obet.no";
|
|
20
|
+
const { APPFRAME_LOGIN: username, APPFRAME_PWD: password } = process.env;
|
|
21
|
+
if (!username || !password) {
|
|
22
|
+
throw new Error("Your Appframe credentials are not set in the environment variables. Username should be set in APPFRAME_LOGIN and password in APPFRAME_PWD.");
|
|
23
|
+
}
|
|
18
24
|
let client = new Client(hostname);
|
|
19
25
|
await client.login(username, password);
|
|
20
26
|
let userResult = await client.afFetch("/api/system/usersession", {
|
|
@@ -55,16 +61,11 @@ export async function createProxyMiddleware() {
|
|
|
55
61
|
});
|
|
56
62
|
return router;
|
|
57
63
|
}
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!username || !password) {
|
|
64
|
-
throw new Error("Your Appframe credentials are not set in the environment variables. Username should be set in APPFRAME_LOGIN and password in APPFRAME_PWD.");
|
|
65
|
-
}
|
|
66
|
-
let userSession = await getUserSession(hostname, username, password);
|
|
67
|
-
return (html) => {
|
|
64
|
+
export function createHtmlTransformer() {
|
|
65
|
+
return async (html) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
let isPartner = ((_b = (_a = appPkg.appframe) === null || _a === void 0 ? void 0 : _a.article) === null || _b === void 0 ? void 0 : _b.hostname) === "partner.olenbetong.no";
|
|
68
|
+
let userSession = await getUserSession();
|
|
68
69
|
return html
|
|
69
70
|
.replace("<!-- {Appframe} -->", `<script>
|
|
70
71
|
af = globalThis.af ?? {};
|
|
@@ -88,14 +89,14 @@ af.userSession = ${JSON.stringify(userSession)};
|
|
|
88
89
|
<link rel="stylesheet" href="/file/site/style/ob.es.application.min.css" />`);
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
|
-
export
|
|
92
|
-
let transformer = await createHtmlTransformer();
|
|
92
|
+
export function createDevMiddleware(vite) {
|
|
93
93
|
return async (req, res, next) => {
|
|
94
|
+
let transformer = createHtmlTransformer();
|
|
94
95
|
const url = req.originalUrl;
|
|
95
96
|
try {
|
|
96
97
|
let template = await fs.readFile(path.resolve(process.cwd(), "index.html"), "utf-8");
|
|
97
98
|
template = await vite.transformIndexHtml(url, template);
|
|
98
|
-
let html = transformer(template);
|
|
99
|
+
let html = await transformer(template);
|
|
99
100
|
res.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
100
101
|
}
|
|
101
102
|
catch (error) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
2
|
import { addAppframeBuildConfig } from "./build.js";
|
|
3
3
|
import { createDevMiddleware, createProxyMiddleware, startDevServer } from "./devServer.js";
|
|
4
|
-
export default function appframe():
|
|
4
|
+
export default function appframe(): Plugin;
|
|
5
5
|
export { addAppframeBuildConfig };
|
|
6
6
|
export { createDevMiddleware, createProxyMiddleware, startDevServer };
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { addAppframeBuildConfig } from "./build.js";
|
|
2
2
|
import { createDevMiddleware, createHtmlTransformer, createProxyMiddleware, startDevServer } from "./devServer.js";
|
|
3
|
-
export default
|
|
4
|
-
let transformIndexHtml =
|
|
3
|
+
export default function appframe() {
|
|
4
|
+
let transformIndexHtml = createHtmlTransformer();
|
|
5
5
|
return {
|
|
6
6
|
name: "appframe",
|
|
7
7
|
async config(_, { command }) {
|