@reldens/server-utils 0.36.0 → 0.38.0

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.
@@ -0,0 +1,57 @@
1
+ /**
2
+ *
3
+ * Reldens - ServerDefaultConfigurations
4
+ *
5
+ */
6
+
7
+ class ServerDefaultConfigurations
8
+ {
9
+
10
+ static get mimeTypes()
11
+ {
12
+ return {
13
+ '.html': 'text/html',
14
+ '.css': 'text/css',
15
+ '.js': 'application/javascript',
16
+ '.json': 'application/json',
17
+ '.xml': 'application/xml',
18
+ '.txt': 'text/plain',
19
+ '.jpg': 'image/jpeg',
20
+ '.jpeg': 'image/jpeg',
21
+ '.png': 'image/png',
22
+ '.gif': 'image/gif',
23
+ '.webp': 'image/webp',
24
+ '.svg': 'image/svg+xml',
25
+ '.ico': 'image/x-icon',
26
+ '.woff': 'font/woff',
27
+ '.woff2': 'font/woff2',
28
+ '.ttf': 'font/ttf',
29
+ '.eot': 'application/vnd.ms-fontobject',
30
+ '.webmanifest': 'application/manifest+json'
31
+ };
32
+ }
33
+
34
+ static get cacheConfig()
35
+ {
36
+ return {
37
+ '.css': 31536000,
38
+ '.js': 31536000,
39
+ '.woff': 31536000,
40
+ '.woff2': 31536000,
41
+ '.ttf': 31536000,
42
+ '.eot': 31536000,
43
+ '.jpg': 2592000,
44
+ '.jpeg': 2592000,
45
+ '.png': 2592000,
46
+ '.gif': 2592000,
47
+ '.webp': 2592000,
48
+ '.svg': 2592000,
49
+ '.ico': 2592000,
50
+ '.xml': 31536000,
51
+ '.webmanifest': 31536000
52
+ };
53
+ }
54
+
55
+ }
56
+
57
+ module.exports.ServerDefaultConfigurations = ServerDefaultConfigurations;
@@ -0,0 +1,56 @@
1
+ /**
2
+ *
3
+ * Reldens - ServerFactoryUtils
4
+ *
5
+ */
6
+
7
+ class ServerFactoryUtils
8
+ {
9
+
10
+ static getCacheConfigForPath(path, cacheConfig)
11
+ {
12
+ if(!cacheConfig){
13
+ return false;
14
+ }
15
+ let cacheKeys = Object.keys(cacheConfig);
16
+ for(let ext of cacheKeys){
17
+ if(path.endsWith(ext)){
18
+ return cacheConfig[ext];
19
+ }
20
+ }
21
+ return false;
22
+ }
23
+
24
+ static validateOrigin(origin, corsOrigins, corsAllowAll)
25
+ {
26
+ if(corsAllowAll){
27
+ return '*';
28
+ }
29
+ if(!origin){
30
+ return false;
31
+ }
32
+ if(0 === corsOrigins.length){
33
+ return false;
34
+ }
35
+ for(let allowedOrigin of corsOrigins){
36
+ if('string' === typeof allowedOrigin && origin === allowedOrigin){
37
+ return origin;
38
+ }
39
+ if(allowedOrigin instanceof RegExp && allowedOrigin.test(origin)){
40
+ return origin;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+
46
+ static stripQueryString(url)
47
+ {
48
+ if(!url){
49
+ return '';
50
+ }
51
+ return url.split('?')[0];
52
+ }
53
+
54
+ }
55
+
56
+ module.exports.ServerFactoryUtils = ServerFactoryUtils;
@@ -0,0 +1,40 @@
1
+ /**
2
+ *
3
+ * Reldens - ServerHeaders
4
+ *
5
+ */
6
+
7
+ class ServerHeaders
8
+ {
9
+
10
+ constructor()
11
+ {
12
+ this.http2SecurityHeaders = {
13
+ 'x-content-type-options': 'nosniff',
14
+ 'x-frame-options': 'DENY'
15
+ };
16
+ this.http2VaryHeader = 'Accept-Encoding, Origin';
17
+ this.http2CorsMethods = 'GET, OPTIONS';
18
+ this.http2CorsHeaders = 'Content-Type';
19
+ this.expressSecurityHeaders = {
20
+ 'X-Content-Type-Options': 'nosniff',
21
+ 'X-Frame-Options': 'DENY'
22
+ };
23
+ this.expressVaryHeader = 'Accept-Encoding';
24
+ this.expressCacheControlNoCache = 'no-cache, no-store, must-revalidate';
25
+ this.expressCacheControlPublic = 'public, max-age={maxAge}, immutable';
26
+ this.expressPragma = 'no-cache';
27
+ this.expressExpires = '0';
28
+ this.proxyForwardedFor = 'X-Forwarded-For';
29
+ this.proxyForwardedProto = 'X-Forwarded-Proto';
30
+ this.proxyForwardedHost = 'X-Forwarded-Host';
31
+ }
32
+
33
+ buildCacheControlHeader(maxAge)
34
+ {
35
+ return this.expressCacheControlPublic.replace('{maxAge}', maxAge);
36
+ }
37
+
38
+ }
39
+
40
+ module.exports.ServerHeaders = ServerHeaders;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/server-utils",
3
3
  "scope": "@reldens",
4
- "version": "0.36.0",
4
+ "version": "0.38.0",
5
5
  "description": "Reldens - Server Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "express-rate-limit": "8.1.0",
44
44
  "express-session": "1.18.2",
45
45
  "helmet": "8.1.0",
46
+ "http-proxy-middleware": "^3.0.5",
46
47
  "multer": "2.0.2",
47
48
  "sanitize-html": "2.17.0"
48
49
  }