jsir 2.5.2 → 2.5.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/deps/room.js CHANGED
@@ -180,7 +180,9 @@ async function syncRooms() {
180
180
  }
181
181
  }
182
182
  if (respBody) {
183
- syncRooms.push(JSON.parse(respBody))
183
+ let currRoom = JSON.parse(respBody);
184
+ currRoom.selfNode = node;
185
+ syncRooms.push(currRoom)
184
186
  debug(`sync ${node} success`);
185
187
  }
186
188
  } catch (e) {
package/deps/server.js CHANGED
@@ -7,6 +7,7 @@ const preferredPort = setting.defaultPort;
7
7
  // 路由存储
8
8
  const routes = setting.routes;
9
9
  let invokeStart = false;
10
+ const apiReg = /[^a-zA-Z]api[^a-zA-Z]|[^a-zA-Z]api$/i;
10
11
 
11
12
  function debug(...args) {
12
13
  if (global.$DEBUG) {
@@ -32,16 +33,10 @@ function createSign() {
32
33
  }
33
34
  }
34
35
 
35
- async function process(routeKey, req, res, params, clientIp) {
36
- if (!clientIp.endsWith(":" + setting.selfRoom.selfNode)) {
37
- res.writeHead(403, {'Content-Type': 'text/plain'});
38
- res.end('Forbidden: Not Allowed');
39
- return;
40
- }
41
-
36
+ async function process(routeKey, req, res, params) {
42
37
  let router = routes[routeKey]
43
38
  if (router) {
44
- if ("get /" !== routeKey && !router.isApi) {
39
+ if ("get /" !== routeKey && !router.isApi && !apiReg.test(routeKey)) {
45
40
  // 如果不是api接口,则校验签名
46
41
  // 取header里的sign字段
47
42
  const sign = req.headers['sign'];
@@ -107,7 +102,7 @@ async function createServer(port) {
107
102
  const routeKey = `${method} ${url}`;
108
103
  let time = Date.now();
109
104
  try {
110
- await process(routeKey, req, res, params, clientIp);
105
+ await process(routeKey, req, res, params);
111
106
  } finally {
112
107
  debug(`Process cost ${Date.now() - time}ms for ${routeKey} from ${clientIp}`);
113
108
  }
@@ -146,7 +141,7 @@ async function startServer() {
146
141
  method, url, fn(req, res, err), null
147
142
  err: {code, msg}
148
143
  */
149
- function setRoute(method, url, fn, handler = jsonHandle, isApi) {
144
+ function setRoute(method, url, fn, isApi = false, handler = jsonHandle) {
150
145
  startServer();
151
146
 
152
147
  const routeKey = `${method.toLowerCase()} ${url}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {