@olenbetong/appframe-vite 4.0.2 → 4.0.4
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/index.js +40 -36
- package/lib/proxy.js +2 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -6,9 +6,10 @@ import { getLastSession, login } from "./proxy.js";
|
|
|
6
6
|
let interval;
|
|
7
7
|
let server;
|
|
8
8
|
let lastHostname;
|
|
9
|
+
let watcher;
|
|
9
10
|
try {
|
|
10
11
|
let appPkgUrl = `file://${process.cwd()}/package.json`;
|
|
11
|
-
watch(appPkgUrl).on("all", async () => {
|
|
12
|
+
watcher = watch(appPkgUrl).on("all", async () => {
|
|
12
13
|
if (server) {
|
|
13
14
|
let { hostname } = await getLoginInfo();
|
|
14
15
|
if (lastHostname !== hostname) {
|
|
@@ -54,46 +55,49 @@ export default function appframe() {
|
|
|
54
55
|
},
|
|
55
56
|
};
|
|
56
57
|
if (command === "build") {
|
|
58
|
+
watcher.close();
|
|
57
59
|
await addAppframeBuildConfig(config);
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (interval)
|
|
65
|
-
clearInterval(interval);
|
|
66
|
-
// After changing the plugin to use the Vite proxy instead of a custom
|
|
67
|
-
// express server with node-http-proxy, we can no longer ensure the requests
|
|
68
|
-
// have a valid login. To reduce the amount of problems we get with expired
|
|
69
|
-
// sessions, we run the login procedure every 5 minutes to renew the session.
|
|
70
|
-
interval = setInterval(async () => {
|
|
61
|
+
else {
|
|
62
|
+
let proxy = config.server?.proxy ?? {};
|
|
63
|
+
let routes = getProxyRoutes();
|
|
64
|
+
let { hostname, username, password } = await getLoginInfo();
|
|
65
|
+
lastHostname = hostname;
|
|
71
66
|
await login(hostname, username, password);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
proxy
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
67
|
+
if (interval)
|
|
68
|
+
clearInterval(interval);
|
|
69
|
+
// After changing the plugin to use the Vite proxy instead of a custom
|
|
70
|
+
// express server with node-http-proxy, we can no longer ensure the requests
|
|
71
|
+
// have a valid login. To reduce the amount of problems we get with expired
|
|
72
|
+
// sessions, we run the login procedure every 5 minutes to renew the session.
|
|
73
|
+
interval = setInterval(async () => {
|
|
74
|
+
await login(hostname, username, password);
|
|
75
|
+
}, 1000 * 60 * 5);
|
|
76
|
+
for (let route of routes) {
|
|
77
|
+
proxy[route] = {
|
|
78
|
+
target: `https://${hostname}`,
|
|
79
|
+
changeOrigin: true,
|
|
80
|
+
configure(proxy, options) {
|
|
81
|
+
proxy.on("proxyReq", (proxyReq, req, res, options) => {
|
|
82
|
+
let authCookies = getLastSession(hostname)?.authCookies;
|
|
83
|
+
if (authCookies) {
|
|
84
|
+
let cookies = [];
|
|
85
|
+
cookies.push(`AppframeWebAuth=${authCookies["AppframeWebAuth"]}`);
|
|
86
|
+
cookies.push(`AppframeWebSession=${authCookies["AppframeWebSession"]}`);
|
|
87
|
+
proxyReq.setHeader("cookie", cookies.join(";"));
|
|
88
|
+
// If left unchanged, the origin will be the local IP address, which makes Appframe
|
|
89
|
+
// return 403 errors
|
|
90
|
+
proxyReq.setHeader("origin", `https://${hostname}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
config.server = {
|
|
97
|
+
...config.server,
|
|
98
|
+
proxy,
|
|
91
99
|
};
|
|
92
100
|
}
|
|
93
|
-
config.server = {
|
|
94
|
-
...config.server,
|
|
95
|
-
proxy,
|
|
96
|
-
};
|
|
97
101
|
return config;
|
|
98
102
|
},
|
|
99
103
|
async configureServer(_server) {
|
package/lib/proxy.js
CHANGED
|
@@ -43,6 +43,7 @@ export async function login(hostname, username, password) {
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
process.stdout.clearLine?.(0);
|
|
46
|
+
process.stdout.cursorTo?.(0);
|
|
46
47
|
write(`\r${chalk.bgBlueBright(hostname)}: Authenticating`);
|
|
47
48
|
let start = performance.now();
|
|
48
49
|
let interval = setInterval(() => {
|
|
@@ -64,6 +65,7 @@ export async function login(hostname, username, password) {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
process.stdout.clearLine?.(0);
|
|
68
|
+
process.stdout.cursorTo?.(0);
|
|
67
69
|
write(`${chalk.bgBlueBright(hostname)}: Authenticated (${Math.floor(performance.now() - start)}ms)\n`);
|
|
68
70
|
lastLogin.set(hostname, {
|
|
69
71
|
timestamp: Date.now(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-vite",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Tools to use and deploy Vite applications to Appframe",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"open": "^9.1.0",
|
|
44
44
|
"tcp-port-used": "^1.0.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "dee9e5d023b626a1ad73a94ab880ab875832cdf6"
|
|
47
47
|
}
|