hola-server 0.4.9 → 0.4.10

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.
Files changed (2) hide show
  1. package/http/express.js +21 -21
  2. package/package.json +1 -1
package/http/express.js CHANGED
@@ -11,6 +11,18 @@ const { asyncLocalStorage, set_context_value } = require('./context');
11
11
  const app = express();
12
12
  let server_initialized = false;
13
13
 
14
+ const is_excluded_url = (server, req) => {
15
+ const exclude_urls = server.exclude_urls;
16
+ for (let i = 0; i < exclude_urls.length; i++) {
17
+ const re = new RegExp(exclude_urls[i], "gim");
18
+ if (re.test(req.originalUrl)) {
19
+ return true;
20
+ }
21
+ }
22
+
23
+ return false;
24
+ }
25
+
14
26
  const init_express_server = (base_dir, callback) => {
15
27
  if (server_initialized === true) {
16
28
  return app;
@@ -25,27 +37,15 @@ const init_express_server = (base_dir, callback) => {
25
37
  init_session(app);
26
38
 
27
39
  app.use((req, res, next) => {
28
- if (server.check_user) {
29
- const exclude_urls = server.exclude_urls;
30
- let excluded = false;
31
- for (let i = 0; i < exclude_urls.length; i++) {
32
- const re = new RegExp(exclude_urls[i], "gim");
33
- if (re.test(req.originalUrl)) {
34
- excluded = true;
35
- break;
36
- }
37
- }
38
-
39
- if (!excluded) {
40
- const user_id = get_session_userid(req);
41
- if (user_id == null) {
42
- res.json({ code: NO_SESSION, err: "no session found" });
43
- } else {
44
- asyncLocalStorage.run({}, () => {
45
- set_context_value("req", req);
46
- next();
47
- });
48
- }
40
+ if (server.check_user && !is_excluded_url(server, req)) {
41
+ const user_id = get_session_userid(req);
42
+ if (user_id == null) {
43
+ res.json({ code: NO_SESSION, err: "no session found" });
44
+ } else {
45
+ asyncLocalStorage.run({}, () => {
46
+ set_context_value("req", req);
47
+ next();
48
+ });
49
49
  }
50
50
  } else {
51
51
  asyncLocalStorage.run({}, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {