vona-core 5.1.40 → 5.1.42

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.js CHANGED
@@ -234,11 +234,16 @@ class AppUtil extends BeanSimple {
234
234
  }
235
235
  get protocol() {
236
236
  const config = this.ctx ? this.ctx.config : this.app.config;
237
- return config.server.serve.protocol || this.ctx?.protocol;
237
+ return config.server.serve.protocol || this.ctx?.protocol || 'http';
238
238
  }
239
239
  get host() {
240
240
  const config = this.ctx ? this.ctx.config : this.app.config;
241
- return config.server.serve.host || this.ctx?.host;
241
+ let host = config.server.serve.host || this.ctx?.host;
242
+ if (!host) {
243
+ const port = this.app.meta.env.SERVER_LISTEN_PORT;
244
+ host = port ? `localhost:${port}` : 'localhost';
245
+ }
246
+ return host;
242
247
  }
243
248
  getAbsoluteUrl(path) {
244
249
  const prefix = this.host ? `${this.protocol}://${this.host}` : '';
@@ -2294,7 +2299,7 @@ const contextBase = {
2294
2299
  } : statusOrOptions ?? {};
2295
2300
  // checkOrigin
2296
2301
  if (!url.startsWith('/') && !options.trustedExternal) {
2297
- const origin = cast(self.app.bean).security.checkOrigin(url, self.host);
2302
+ const origin = cast(self.app.bean).security.checkOrigin(url, self.app.util.host);
2298
2303
  if (!origin) self.app.throw(403);
2299
2304
  }
2300
2305
  // throw
@@ -2678,22 +2683,28 @@ class VonaApplication extends KoaApplication {
2678
2683
  if (req) {
2679
2684
  request = req;
2680
2685
  } else {
2681
- const host = `localhost:${this.meta.env.SERVER_LISTEN_PORT}`;
2686
+ const protocol = 'http';
2687
+ const port = this.meta.env.SERVER_LISTEN_PORT;
2688
+ const host = port ? `localhost:${port}` : 'localhost';
2689
+ const hostname = new URL(`${protocol}://${host}`).hostname;
2682
2690
  request = {
2683
2691
  headers: {
2684
2692
  'host': host,
2685
- 'x-forwarded-for': host
2693
+ 'x-forwarded-for': '127.0.0.1',
2694
+ 'x-forwarded-host': host,
2695
+ 'x-forwarded-proto': protocol
2686
2696
  },
2687
2697
  query: {},
2688
2698
  querystring: '',
2689
2699
  host,
2690
- hostname: 'localhost',
2691
- protocol: 'http',
2692
- secure: 'false',
2700
+ hostname,
2701
+ protocol,
2702
+ secure: false,
2693
2703
  method: 'POST',
2694
2704
  url: '',
2695
2705
  path: '',
2696
2706
  socket: {
2707
+ encrypted: false,
2697
2708
  remoteAddress: '127.0.0.1',
2698
2709
  remotePort: 7001
2699
2710
  }