@azteam/express 1.2.186 → 1.2.187
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 +1 -1
- package/src/Server.js +3 -3
- package/src/SocketServer.js +5 -6
package/package.json
CHANGED
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 {errorCatch, ErrorException, NOT_FOUND, UNKNOWN} from '@azteam/error';
|
|
13
|
+
import {errorCatch, ErrorException, NOT_FOUND, UNKNOWN, CORS} from '@azteam/error';
|
|
14
14
|
|
|
15
15
|
const RES_TYPE = {
|
|
16
16
|
ARRAY: 'ARRAY',
|
|
@@ -140,11 +140,11 @@ class Server {
|
|
|
140
140
|
app.use(
|
|
141
141
|
cors({
|
|
142
142
|
credentials: true,
|
|
143
|
-
origin
|
|
143
|
+
origin(origin, callback) {
|
|
144
144
|
if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
|
|
145
145
|
callback(null, true);
|
|
146
146
|
} else {
|
|
147
|
-
callback(new
|
|
147
|
+
callback(new ErrorException(CORS, `${origin} Not allowed by CORS`));
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
150
|
})
|
package/src/SocketServer.js
CHANGED
|
@@ -56,6 +56,7 @@ class SocketServer {
|
|
|
56
56
|
const versionDirs = fs.readdirSync(`${apiDir}/${dirName}`);
|
|
57
57
|
|
|
58
58
|
for (const versionName of versionDirs) {
|
|
59
|
+
// eslint-disable-next-line import/no-dynamic-require,global-require
|
|
59
60
|
const controller = require(`${apiDir}/${dirName}/${versionName}/controller`).default;
|
|
60
61
|
this.addController(dirName, versionName, controller);
|
|
61
62
|
}
|
|
@@ -83,7 +84,7 @@ class SocketServer {
|
|
|
83
84
|
},
|
|
84
85
|
cors: {
|
|
85
86
|
credentials: true,
|
|
86
|
-
origin
|
|
87
|
+
origin(origin, callback) {
|
|
87
88
|
if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
|
|
88
89
|
callback(null, true);
|
|
89
90
|
} else {
|
|
@@ -99,7 +100,7 @@ class SocketServer {
|
|
|
99
100
|
|
|
100
101
|
const msg = [];
|
|
101
102
|
_.map(this.controllers, (obj) => {
|
|
102
|
-
const controller = obj
|
|
103
|
+
const {controller} = obj;
|
|
103
104
|
|
|
104
105
|
_.map(controller, (item, key) => {
|
|
105
106
|
item.path = obj.version.startsWith('v') ? `/${obj.version}${item.path}` : item.path;
|
|
@@ -145,7 +146,7 @@ class SocketServer {
|
|
|
145
146
|
throw error;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
let bind = typeof port === 'string' ?
|
|
149
|
+
let bind = typeof port === 'string' ? `Pipe ${port}` : `Port ${port}`;
|
|
149
150
|
|
|
150
151
|
switch (error.code) {
|
|
151
152
|
case 'EACCES':
|
|
@@ -164,10 +165,8 @@ class SocketServer {
|
|
|
164
165
|
server.listen(port);
|
|
165
166
|
|
|
166
167
|
return server;
|
|
167
|
-
} else {
|
|
168
|
-
throw Error('No controllers in use');
|
|
169
168
|
}
|
|
170
|
-
|
|
169
|
+
throw Error('No controllers in use');
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
setAlertCallback(callback) {
|