@azteam/express 1.2.215 → 1.2.218

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": "@azteam/express",
3
- "version": "1.2.215",
3
+ "version": "1.2.218",
4
4
  "main": "src/index.js",
5
5
  "engines": {
6
6
  "node": ">= 12.0.0",
@@ -10,7 +10,7 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@azteam/crypto": "1.0.24",
13
- "@azteam/error": "1.0.25",
13
+ "@azteam/error": "1.0.26",
14
14
  "@azteam/http-client": "1.0.95",
15
15
  "@grpc/grpc-js": "1.6.7",
16
16
  "@grpc/proto-loader": "0.6.12",
package/src/Server.js CHANGED
@@ -10,7 +10,7 @@ import morgan from 'morgan';
10
10
  import cors from 'cors';
11
11
  import _ from 'lodash';
12
12
  import 'express-async-errors';
13
- import {CORS, errorCatch, ErrorException, UNKNOWN} from '@azteam/error';
13
+ import {CORS, errorCatch, ErrorException, NOT_FOUND, UNKNOWN} from '@azteam/error';
14
14
 
15
15
  import {authMiddleware} from './middleware/authMiddleware';
16
16
 
@@ -269,7 +269,7 @@ class Server {
269
269
  next();
270
270
  });
271
271
 
272
- _.map(this.middlewares, (middleware) => {
272
+ _.map(this.middlewares, function (middleware) {
273
273
  app.use(middleware);
274
274
  });
275
275
 
@@ -307,11 +307,15 @@ class Server {
307
307
 
308
308
  console.table(msg);
309
309
 
310
- app.all('/', async (req, res) => {
310
+ app.all('/', async function (req, res) {
311
311
  return res.success('welcome');
312
312
  });
313
313
 
314
- app.use((err, req, res, next) => {
314
+ app.use(function (req, res) {
315
+ throw new ErrorException(NOT_FOUND);
316
+ });
317
+
318
+ app.use(function (err, req, res, next) {
315
319
  const error = errorCatch(err);
316
320
 
317
321
  if (process.env.NODE_ENV === 'development') {
@@ -1,5 +1,5 @@
1
1
  import jwt from 'jsonwebtoken';
2
- import {ErrorException, TOKEN_EXPIRED, TOKEN_FAILED, UNKNOWN} from '@azteam/error';
2
+ import {ErrorException, TOKEN_EXPIRED, TOKEN_FAILED} from '@azteam/error';
3
3
 
4
4
  function systemLogin(userData = null) {
5
5
  let user = {};
@@ -24,8 +24,8 @@ export function authMiddleware(req, res, next) {
24
24
  }
25
25
 
26
26
  if (token) {
27
- if (token.startsWith('JWT ')) {
28
- token = token.replace('JWT ', '');
27
+ if (token.startsWith('Bearer ')) {
28
+ token = token.replace('Bearer ', '');
29
29
 
30
30
  try {
31
31
  req.user = jwt.verify(token, process.env.SECRET_KEY);
@@ -34,10 +34,12 @@ export function authMiddleware(req, res, next) {
34
34
  if (err.name === 'TokenExpiredError') {
35
35
  throw new ErrorException(TOKEN_EXPIRED, err);
36
36
  }
37
- throw new ErrorException(UNKNOWN, err);
37
+ throw new ErrorException(TOKEN_FAILED, err);
38
38
  }
39
39
  }
40
- throw new ErrorException(TOKEN_FAILED, ['Token type failed']);
40
+ throw new ErrorException(TOKEN_FAILED, {
41
+ message: 'Token type invalid',
42
+ });
41
43
  }
42
44
  }
43
45