@olenbetong/appframe-vite 1.0.5 → 1.1.0
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 +1 -1
- package/lib/devServer.js +11 -11
- package/lib/index.js +3 -3
- package/lib/proxy.d.ts +1 -1
- package/lib/proxy.js +2 -5
- 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
|
-
export declare function createProxyMiddleware():
|
|
3
|
+
export declare function createProxyMiddleware(): Router;
|
|
4
4
|
export declare function createHtmlTransformer(): (html: string) => Promise<string>;
|
|
5
5
|
export declare function createDevMiddleware(vite: ViteDevServer): RequestHandler;
|
|
6
6
|
export declare function startDevServer(app: Application): Promise<void>;
|
package/lib/devServer.js
CHANGED
|
@@ -12,15 +12,10 @@ let appPkg = await importJson("./package.json", true);
|
|
|
12
12
|
let { appframe } = appPkg;
|
|
13
13
|
let userSession = null;
|
|
14
14
|
async function getUserSession() {
|
|
15
|
-
var _a, _b, _c, _d;
|
|
16
15
|
if (userSession) {
|
|
17
16
|
return userSession;
|
|
18
17
|
}
|
|
19
|
-
|
|
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
|
+
let { hostname, username, password } = getLoginInfo();
|
|
24
19
|
let client = new Client(hostname);
|
|
25
20
|
await client.login(username, password);
|
|
26
21
|
let userResult = await client.afFetch("/api/system/usersession", {
|
|
@@ -29,15 +24,19 @@ async function getUserSession() {
|
|
|
29
24
|
userSession = await userResult.json();
|
|
30
25
|
return userSession;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
var _a, _b, _c, _d
|
|
27
|
+
function getLoginInfo() {
|
|
28
|
+
var _a, _b, _c, _d;
|
|
34
29
|
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";
|
|
35
30
|
const { APPFRAME_LOGIN: username, APPFRAME_PWD: password } = process.env;
|
|
36
|
-
const router = express.Router();
|
|
37
31
|
if (!username || !password) {
|
|
38
32
|
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.");
|
|
39
33
|
}
|
|
40
|
-
|
|
34
|
+
return { hostname, username, password };
|
|
35
|
+
}
|
|
36
|
+
export function createProxyMiddleware() {
|
|
37
|
+
var _a;
|
|
38
|
+
let { hostname, username, password } = getLoginInfo();
|
|
39
|
+
const proxy = createAppframeProxy({ hostname, username, password });
|
|
41
40
|
const proxyRoutes = [
|
|
42
41
|
"/api/*",
|
|
43
42
|
"/file/*",
|
|
@@ -53,9 +52,10 @@ export async function createProxyMiddleware() {
|
|
|
53
52
|
"/rowcount/*",
|
|
54
53
|
"/lib/*"
|
|
55
54
|
];
|
|
56
|
-
if ((
|
|
55
|
+
if ((_a = appframe.proxy) === null || _a === void 0 ? void 0 : _a.routes) {
|
|
57
56
|
proxyRoutes.push(...appframe.proxy.routes);
|
|
58
57
|
}
|
|
58
|
+
const router = express.Router();
|
|
59
59
|
proxyRoutes.forEach(route => {
|
|
60
60
|
router.use(route, proxy);
|
|
61
61
|
});
|
package/lib/index.js
CHANGED
|
@@ -17,9 +17,9 @@ export default function appframe() {
|
|
|
17
17
|
return config;
|
|
18
18
|
},
|
|
19
19
|
async configureServer(_server) {
|
|
20
|
-
_server.middlewares.use(
|
|
21
|
-
return
|
|
22
|
-
_server.middlewares.use(
|
|
20
|
+
_server.middlewares.use(createProxyMiddleware());
|
|
21
|
+
return () => {
|
|
22
|
+
_server.middlewares.use(createDevMiddleware(_server));
|
|
23
23
|
};
|
|
24
24
|
},
|
|
25
25
|
transformIndexHtml
|
package/lib/proxy.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export declare type createProxyOptions = {
|
|
|
11
11
|
password: string;
|
|
12
12
|
protocol?: "http" | "https";
|
|
13
13
|
};
|
|
14
|
-
export declare function createAppframeProxy(options: createProxyOptions):
|
|
14
|
+
export declare function createAppframeProxy(options: createProxyOptions): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
package/lib/proxy.js
CHANGED
|
@@ -63,8 +63,8 @@ export async function login(hostname, username, password) {
|
|
|
63
63
|
currentLogin = null;
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
66
|
-
export
|
|
67
|
-
const {
|
|
66
|
+
export function createAppframeProxy(options) {
|
|
67
|
+
const { hostname, password, protocol = "https", username } = options;
|
|
68
68
|
const proxy = expressProxy(`${protocol}://${hostname}`, {
|
|
69
69
|
proxyReqOptDecorator: async function (proxyReqOpts) {
|
|
70
70
|
var _a, _b;
|
|
@@ -82,8 +82,5 @@ export async function createAppframeProxy(options) {
|
|
|
82
82
|
return req.originalUrl;
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
|
-
if (autoLogin) {
|
|
86
|
-
await login(hostname, username, password);
|
|
87
|
-
}
|
|
88
85
|
return proxy;
|
|
89
86
|
}
|