tom-microservice 3.8.0 → 3.9.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/README.md +1 -1
- package/package.json +1 -1
- package/src/routes.js +3 -2
package/README.md
CHANGED
|
@@ -466,7 +466,7 @@ See [cors](https://github.com/expressjs/cors#configuration-options) for more inf
|
|
|
466
466
|
Type: `string` </br>
|
|
467
467
|
Default: `undefined`
|
|
468
468
|
|
|
469
|
-
When you provide it, all request to **tom** 🐶 needs to be authenticated using `x-api-key`
|
|
469
|
+
When you provide it, all request to **tom** 🐶 needs to be authenticated using `req.headers[`x-api-key`] or `req.query.apiKey` and the value provided.
|
|
470
470
|
|
|
471
471
|
You can use [randomkeygen.com](https://randomkeygen.com) for that.
|
|
472
472
|
|
package/package.json
CHANGED
package/src/routes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { eq, forEach, noop } = require('lodash')
|
|
4
4
|
const { buffer, text } = require('http-body')
|
|
5
5
|
const requestIp = require('request-ip')
|
|
6
6
|
const toQuery = require('to-query')()
|
|
@@ -78,7 +78,8 @@ const createRouter = () => {
|
|
|
78
78
|
if (TOM_API_KEY) {
|
|
79
79
|
router.use((req, res, next) => {
|
|
80
80
|
if (UNAUTHENTICATED_PATHS.includes(req.path)) return next()
|
|
81
|
-
const apiKey =
|
|
81
|
+
const apiKey = req.headers['x-api-key'] ?? req.query.apiKey
|
|
82
|
+
|
|
82
83
|
return eq(apiKey, TOM_API_KEY)
|
|
83
84
|
? next()
|
|
84
85
|
: send.fail(
|