lieko-express 0.0.9 → 0.0.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.
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,10 @@ ${cyan} (req, res, next) => {
881
911
  }
882
912
 
883
913
  async _handleRequest(req, res) {
914
+ if (this._isExcluded(req.url.split('?')[0])) {
915
+ return res.status(404).end();
916
+ }
917
+
884
918
  this._enhanceRequest(req);
885
919
 
886
920
  const url = req.url;
@@ -1243,7 +1277,6 @@ ${cyan} (req, res, next) => {
1243
1277
  const locals = { ...res.locals, ...options };
1244
1278
  let viewPath = view;
1245
1279
  let ext = path.extname(view);
1246
- console.log("EXT: ", ext)
1247
1280
 
1248
1281
  if (!ext) {
1249
1282
  ext = this.settings['view engine'];
@@ -1258,13 +1291,11 @@ ${cyan} (req, res, next) => {
1258
1291
 
1259
1292
  const viewsDir = this.settings.views || path.join(process.cwd(), 'views');
1260
1293
  let fullPath = path.join(viewsDir, viewPath);
1261
- console.log(fullPath)
1262
1294
  let fileExists = false;
1263
1295
  try {
1264
1296
  await fs.promises.access(fullPath);
1265
1297
  fileExists = true;
1266
1298
  } catch (err) {
1267
- console.log(err)
1268
1299
  const extensions = ['.html', '.ejs', '.pug', '.hbs'];
1269
1300
  for (const tryExt of extensions) {
1270
1301
  if (tryExt === ext) continue;
@@ -1314,12 +1345,6 @@ ${cyan} (req, res, next) => {
1314
1345
  callback(null, html);
1315
1346
  resolve();
1316
1347
  } 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
1348
  res.html(html);
1324
1349
  resolve();
1325
1350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lieko-express",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eiwSrvt/lieko-express"