@tuya-sat/micro-dev-proxy 2.2.18 → 2.2.21

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/appProxy.js CHANGED
@@ -56,7 +56,6 @@ class AppProxy {
56
56
  this.log = (0, util_1.logFactory)(logSign);
57
57
  this.csrf = csrf;
58
58
  Object.assign(globalAxios_1.default.defaults.headers.common, this.additionHeaders);
59
- this.init();
60
59
  }
61
60
  init() {
62
61
  return __awaiter(this, void 0, void 0, function* () {
@@ -69,7 +68,7 @@ class AppProxy {
69
68
  //获取csrf
70
69
  getCsrf() {
71
70
  return __awaiter(this, void 0, void 0, function* () {
72
- yield (0, csrf_1.default)(this.target)
71
+ yield (0, csrf_1.default)(new url_1.URL("/login", this.target).href)
73
72
  .then(([cookie, value]) => {
74
73
  this.csrfCookie.setValue(cookie);
75
74
  this.csrfValue.setValue(value);
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export interface Config extends AppProxyConfig {
4
4
  [key: string]: any;
5
5
  };
6
6
  }
7
+ export declare function awaiting(): any[];
7
8
  export default function createProxy({ additionHeaders, ...restPrevConfig }: Config): (app: any) => void;
package/dist/index.js CHANGED
@@ -14,15 +14,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.awaiting = void 0;
17
18
  const os_1 = __importDefault(require("os"));
18
19
  const http_proxy_middleware_1 = require("http-proxy-middleware");
19
20
  const appProxy_1 = __importDefault(require("./appProxy"));
21
+ function awaiting() {
22
+ let $resolve, $reject;
23
+ const waiting = new Promise((resolve, reject) => {
24
+ $resolve = resolve;
25
+ $reject = reject;
26
+ });
27
+ return [$resolve, $reject, waiting];
28
+ }
29
+ exports.awaiting = awaiting;
20
30
  function createProxy(_a) {
21
31
  var { additionHeaders = {} } = _a, restPrevConfig = __rest(_a, ["additionHeaders"]);
22
32
  const config = Object.assign({ additionHeaders: Object.assign({ terminalId: os_1.default.hostname() }, additionHeaders), isMainApp: false, loginApi: "/api/login", needProxyApi: ["/api", "/open-api"], logSign: false, csrf: true }, restPrevConfig);
23
33
  const { needProxyApi } = config, appProxyConfig = __rest(config, ["needProxyApi"]);
24
34
  const appProxy = new appProxy_1.default(appProxyConfig);
25
35
  return function middleware(app) {
36
+ const [resolve, , waiting] = awaiting();
37
+ app._isLogin = waiting;
38
+ appProxy.init().finally(() => {
39
+ resolve();
40
+ });
26
41
  app.use(needProxyApi, (0, http_proxy_middleware_1.createProxyMiddleware)({
27
42
  target: appProxyConfig.target,
28
43
  changeOrigin: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-proxy",
3
- "version": "2.2.18",
3
+ "version": "2.2.21",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {