waibu 1.2.3 → 1.2.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/index.js CHANGED
@@ -22,7 +22,7 @@ async function factory (pkgName) {
22
22
  this.dependencies = ['bajo-logger', 'bajo-extra']
23
23
  this.config = {
24
24
  server: {
25
- host: '0.0.0.0',
25
+ address: '127.0.0.1',
26
26
  port: 7771
27
27
  },
28
28
  factory: {
@@ -185,6 +185,13 @@ async function factory (pkgName) {
185
185
  return fwd[0] ?? req.ip
186
186
  }
187
187
 
188
+ getOrigin = (req) => {
189
+ const { isEmpty } = this.lib._
190
+ let host = req.host
191
+ if (isEmpty(host) || host === ':authority') host = `${this.config.server.address}:${this.config.server.port}`
192
+ return `${req.protocol}://${host}`
193
+ }
194
+
188
195
  getPluginByPrefix = (prefix) => {
189
196
  const { get, find } = this.lib._
190
197
  const item = find(this.app.waibu.routes, r => {
@@ -287,7 +294,7 @@ async function factory (pkgName) {
287
294
  if (options.uriEncoded) url = url.split('/').map(u => encodeURI(u)).join('/')
288
295
  info.qs = defaultsDeep({}, query, info.qs)
289
296
  if (!isEmpty(info.qs)) url += '?' + this.qs.stringify(info.qs)
290
- if (!url.startsWith('http') && guessHost) url = `http://${this.config.server.host}:${this.config.server.port}/${trimStart(url, '/')}`
297
+ if (!url.startsWith('http') && guessHost) url = `http://${this.config.server.address}:${this.config.server.port}/${trimStart(url, '/')}`
291
298
  return url
292
299
  }
293
300
 
@@ -11,7 +11,7 @@ async function handleForward (ctx) {
11
11
  }
12
12
  }
13
13
 
14
- const base = `http://${this.config.server.host}:${this.config.server.port}`
14
+ const base = `http://${this.config.server.address}:${this.config.server.port}`
15
15
  const options = defaultsDeep({ base }, this.config.forwardOpts)
16
16
  await ctx.register(replyFrom, options)
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {