hola-server 0.6.2 → 0.6.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/core/file.js +8 -1
- package/http/cors.js +7 -5
- package/http/express.js +6 -2
- package/http/router.js +12 -10
- package/http/session.js +1 -1
- package/package.json +1 -1
package/core/file.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fs_promises = require('fs').promises;
|
|
3
|
+
|
|
2
4
|
const unzipper = require('unzipper');
|
|
3
5
|
|
|
4
6
|
const file_extension = file_name => file_name ? file_name.split('.').pop() : "";
|
|
@@ -28,4 +30,9 @@ const is_file_exist = (path) => {
|
|
|
28
30
|
return true;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
const get_file_size = async (path) => {
|
|
34
|
+
const stats = await fs_promises.stat(path);
|
|
35
|
+
return stats.size;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { file_extension, file_prefix, read_from_zip_by_extension, read_from_zip_by_prefix, is_file_exist, get_file_size }
|
package/http/cors.js
CHANGED
|
@@ -3,11 +3,13 @@ const { get_settings } = require('../setting');
|
|
|
3
3
|
|
|
4
4
|
const init_cors = (app) => {
|
|
5
5
|
const server = get_settings().server;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
if (server && server.client_web_url) {
|
|
7
|
+
app.use(cors({
|
|
8
|
+
origin: server.client_web_url,
|
|
9
|
+
methods: ['GET', 'POST'],
|
|
10
|
+
credentials: true
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
module.exports = { init_cors };
|
package/http/express.js
CHANGED
|
@@ -32,8 +32,12 @@ const init_express_server = (base_dir, port_attr, callback) => {
|
|
|
32
32
|
const threshold = server.threshold;
|
|
33
33
|
|
|
34
34
|
init_cors(app);
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
|
|
36
|
+
if (threshold) {
|
|
37
|
+
app.use(express.json({ limit: threshold.body_limit, extended: true }));
|
|
38
|
+
app.use(express.urlencoded({ limit: threshold.body_limit, extended: true }));
|
|
39
|
+
}
|
|
40
|
+
|
|
37
41
|
init_session(app);
|
|
38
42
|
|
|
39
43
|
app.use((req, res, next) => {
|
package/http/router.js
CHANGED
|
@@ -18,18 +18,20 @@ const { get_settings } = require('../setting');
|
|
|
18
18
|
const init_router_dirs = (app, base_dir) => {
|
|
19
19
|
const route_dirs = get_settings().server.routes;
|
|
20
20
|
|
|
21
|
-
route_dirs
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (route_dirs) {
|
|
22
|
+
route_dirs.forEach(route_dir => {
|
|
23
|
+
const full_route_dir = path.join(base_dir, route_dir);
|
|
24
|
+
const routes = fs.readdirSync(full_route_dir);
|
|
25
|
+
routes.forEach(route => {
|
|
26
|
+
const router = require(`${base_dir}/${route_dir}/${route}`);
|
|
27
|
+
const basename = path.basename(route, '.js');
|
|
28
|
+
app.use('/' + basename, router);
|
|
29
|
+
});
|
|
28
30
|
});
|
|
29
|
-
});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
//after init all the router, then validate all the meta informations
|
|
33
|
+
validate_all_metas();
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/**
|
package/http/session.js
CHANGED