lieko-express 0.0.9 → 0.0.11

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/lib/cors.js CHANGED
@@ -97,4 +97,4 @@ module.exports = function cors(userOptions = {}) {
97
97
  }
98
98
  next();
99
99
  };
100
- };
100
+ };
package/lib/static.js CHANGED
@@ -244,4 +244,4 @@ module.exports = function serveStatic(root, options = {}) {
244
244
  res.status(500).send('Internal Server Error');
245
245
  }
246
246
  };
247
- };
247
+ };
package/lieko-express.js CHANGED
@@ -61,6 +61,36 @@ class LiekoExpress {
61
61
  exposedHeaders: [],
62
62
  debug: false
63
63
  };
64
+
65
+ this.excludedPatterns = [
66
+ /^\/\.well-known\/.*/i // Chrome DevTools, Apple, etc.
67
+ ]
68
+ }
69
+
70
+ excludeUrl(patterns) {
71
+ if (!Array.isArray(patterns)) patterns = [patterns];
72
+ this.excludedPatterns = this.excludedPatterns || [];
73
+
74
+ patterns.forEach(pattern => {
75
+ if (pattern instanceof RegExp) {
76
+ this.excludedPatterns.push(pattern);
77
+ return;
78
+ }
79
+
80
+ let regexStr = pattern
81
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
82
+ .replace(/\\\*/g, '.*');
83
+
84
+ regexStr = '^' + regexStr + '$';
85
+ this.excludedPatterns.push(new RegExp(regexStr, 'i'));
86
+ });
87
+
88
+ return this;
89
+ }
90
+
91
+ _isExcluded(url) {
92
+ if (!this.excludedPatterns?.length) return false;
93
+ return this.excludedPatterns.some(re => re.test(url));
64
94
  }
65
95
 
66
96
  cors(options = {}) {
@@ -881,6 +911,11 @@ ${cyan} (req, res, next) => {
881
911
  }
882
912
 
883
913
  async _handleRequest(req, res) {
914
+ if (this._isExcluded(req.url.split('?')[0])) {
915
+ res.statusCode = 404;
916
+ return res.end();
917
+ }
918
+
884
919
  this._enhanceRequest(req);
885
920
 
886
921
  const url = req.url;
@@ -1243,7 +1278,6 @@ ${cyan} (req, res, next) => {
1243
1278
  const locals = { ...res.locals, ...options };
1244
1279
  let viewPath = view;
1245
1280
  let ext = path.extname(view);
1246
- console.log("EXT: ", ext)
1247
1281
 
1248
1282
  if (!ext) {
1249
1283
  ext = this.settings['view engine'];
@@ -1258,13 +1292,11 @@ ${cyan} (req, res, next) => {
1258
1292
 
1259
1293
  const viewsDir = this.settings.views || path.join(process.cwd(), 'views');
1260
1294
  let fullPath = path.join(viewsDir, viewPath);
1261
- console.log(fullPath)
1262
1295
  let fileExists = false;
1263
1296
  try {
1264
1297
  await fs.promises.access(fullPath);
1265
1298
  fileExists = true;
1266
1299
  } catch (err) {
1267
- console.log(err)
1268
1300
  const extensions = ['.html', '.ejs', '.pug', '.hbs'];
1269
1301
  for (const tryExt of extensions) {
1270
1302
  if (tryExt === ext) continue;
@@ -1314,12 +1346,6 @@ ${cyan} (req, res, next) => {
1314
1346
  callback(null, html);
1315
1347
  resolve();
1316
1348
  } else {
1317
- /*
1318
- HBS cause error header already sent here ??
1319
- */
1320
- //res.statusCode = statusCode || 200;
1321
- //res.setHeader('Content-Type', 'text/html; charset=utf-8');
1322
- //responseSent = true;
1323
1349
  res.html(html);
1324
1350
  resolve();
1325
1351
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lieko-express",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eiwSrvt/lieko-express"