@athenna/http 1.8.3 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "description": "The Athenna Http server. Built on top of fastify.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -54,11 +54,11 @@
54
54
  "#tests/*": "./tests/*.js"
55
55
  },
56
56
  "dependencies": {
57
- "@athenna/artisan": "1.6.0",
57
+ "@athenna/artisan": "1.6.2",
58
58
  "@athenna/common": "1.0.2",
59
- "@athenna/config": "1.2.1",
60
- "@athenna/ioc": "1.3.0",
61
- "@athenna/logger": "1.3.8",
59
+ "@athenna/config": "1.2.2",
60
+ "@athenna/ioc": "1.3.1",
61
+ "@athenna/logger": "1.4.0",
62
62
  "@fastify/cors": "8.1.1",
63
63
  "@fastify/helmet": "10.0.2",
64
64
  "@fastify/rate-limit": "7.5.0",
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { Config } from '@athenna/config'
11
11
  import { Is, Json } from '@athenna/common'
12
+ import { Server } from '#src/index'
12
13
 
13
14
  export class Request {
14
15
  /**
@@ -52,7 +53,7 @@ export class Request {
52
53
  * @return {string}
53
54
  */
54
55
  get hostUrl() {
55
- const port = Config.get('http.port', 1335)
56
+ const port = Config.get('http.port', Server.getPort())
56
57
  let host = Config.get('http.domain', `http://localhost:${port}`)
57
58
 
58
59
  if (!Is.Ip(host) && !host.includes('localhost')) {
@@ -10,6 +10,6 @@
10
10
  import { Facade } from '@athenna/ioc'
11
11
 
12
12
  /**
13
- * @type {Facade & import('../Router/Router.js').Router}
13
+ * @type {typeof Facade & import('../Router/Router.js').Router}
14
14
  */
15
15
  export const Route = Facade.createFor('Athenna/Core/HttpRoute')
@@ -10,6 +10,6 @@
10
10
  import { Facade } from '@athenna/ioc'
11
11
 
12
12
  /**
13
- * @type {Facade & import('../index.js').Http}
13
+ * @type {typeof Facade & import('../index.js').Http}
14
14
  */
15
15
  export const Server = Facade.createFor('Athenna/Core/HttpServer')
@@ -93,7 +93,7 @@ export class HttpKernel {
93
93
  * @return {Promise<void>}
94
94
  */
95
95
  async registerCors() {
96
- if (Config.get('http.noCors')) {
96
+ if (Config.is('http.noCors', true)) {
97
97
  return
98
98
  }
99
99
 
@@ -106,7 +106,7 @@ export class HttpKernel {
106
106
  * @return {Promise<void>}
107
107
  */
108
108
  async registerHelmet() {
109
- if (Config.get('http.noHelmet')) {
109
+ if (Config.is('http.noHelmet', true)) {
110
110
  return
111
111
  }
112
112
 
@@ -119,7 +119,7 @@ export class HttpKernel {
119
119
  * @return {Promise<void>}
120
120
  */
121
121
  async registerSwagger() {
122
- if (Config.get('http.noSwagger')) {
122
+ if (Config.is('http.noSwagger', true)) {
123
123
  return
124
124
  }
125
125
 
@@ -132,7 +132,7 @@ export class HttpKernel {
132
132
  * @return {Promise<void>}
133
133
  */
134
134
  async registerRateLimit() {
135
- if (Config.get('http.noRateLimit')) {
135
+ if (Config.is('http.noRateLimit', true)) {
136
136
  return
137
137
  }
138
138
 
@@ -145,7 +145,7 @@ export class HttpKernel {
145
145
  * @return {Promise<void>}
146
146
  */
147
147
  async registerErrorHandler() {
148
- if (Config.get('http.noErrorHandler')) {
148
+ if (Config.is('http.noErrorHandler', true)) {
149
149
  return
150
150
  }
151
151
 
@@ -162,7 +162,7 @@ export class HttpKernel {
162
162
  * @return {Promise<void>}
163
163
  */
164
164
  async registerLogMiddleware() {
165
- if (!Config.get('http.logRequests')) {
165
+ if (Config.is('http.logRequests', false)) {
166
166
  return
167
167
  }
168
168
 
@@ -177,7 +177,7 @@ export class HttpKernel {
177
177
  * @return {Promise<void>}
178
178
  */
179
179
  async registerRequestIdMiddleware() {
180
- if (Config.get('http.noRequestId')) {
180
+ if (Config.is('http.noRequestId', true)) {
181
181
  return
182
182
  }
183
183
 
package/src/index.d.ts CHANGED
@@ -210,6 +210,13 @@ export class Http {
210
210
  */
211
211
  getRoutes(options?: import('fastify').PrintRoutesOptions): string
212
212
 
213
+ /**
214
+ * Get the server port where http is being running.
215
+ *
216
+ * @return {number}
217
+ */
218
+ getPort(): number
219
+
213
220
  /**
214
221
  * Print all routes registered.
215
222
  *
package/src/index.js CHANGED
@@ -155,6 +155,15 @@ export class Http {
155
155
  return this.#server.printRoutes(options)
156
156
  }
157
157
 
158
+ /**
159
+ * Get the server port where http is being running.
160
+ *
161
+ * @return {number}
162
+ */
163
+ getPort() {
164
+ return this.#server.server.address().port
165
+ }
166
+
158
167
  /**
159
168
  * Print all routes registered.
160
169
  *
@@ -203,7 +212,7 @@ export class Http {
203
212
  * @param {string} [host]
204
213
  * @return {Promise<string>}
205
214
  */
206
- async listen(port = 1335, host = '0.0.0.0') {
215
+ async listen(port = 0, host = '0.0.0.0') {
207
216
  this.#isListening = true
208
217
 
209
218
  return this.#server.listen({ port, host })