Code "quality" enforcement.

This commit is contained in:
Andrew Pietila 2023-03-21 06:51:25 -05:00
parent 8b0b3fd2ef
commit c4882652e5
7 changed files with 1805 additions and 19 deletions

15
.editorconfig Normal file
View file

@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{yaml,yml}]
indent_size = 2

54
.eslintrc.json Normal file
View file

@ -0,0 +1,54 @@
{
"env": {
"browser": false,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"quote-props": [
"error",
"consistent-as-needed"
],
"padded-blocks": [
"error",
"never"
],
"one-var": [
"error",
"never"
],
"function-call-argument-newline": [
"error",
"consistent"
]
}
}

14
.license-check.yaml Normal file
View file

@ -0,0 +1,14 @@
---
allowedLicenses:
- (MIT AND CC-BY-3.0)
- (MIT OR CC0-1.0)
- Apache-2.0
- BSD-2-Clause
- BSD-3-Clause
- BlueOak-1.0.0
- CC0-1.0
- CC-BY-3.0
- ISC
- MIT
- Python-2.0
- WTFPL

16
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,16 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.36.0
hooks:
- id: eslint
- repo: https://github.com/kontrolilo/kontrolilo
rev: v2.1.0
hooks:
- id: license-check-npm

41
app.js
View file

@ -1,5 +1,6 @@
'use strict';
const express = require('express');
const fsPromises = require('fs').promises;
const glob = require('glob');
const { match: createPathMatch } = require('path-to-regexp');
@ -10,43 +11,45 @@ const { match: createPathMatch } = require('path-to-regexp');
dot: true,
});
const pathMatches = [];
app.use(async (req, res, next) => {
const requestUrl = new URL(req.url, "https://example.com/");
var candidateUrl = "";
var secondCandidateUrl = "";
for ( let pathMatch in pathMatches ) {
if ( patchMatches[pathMatch](requestUrl.pathname) ) {
app.use((req, res, next) => {
const requestUrl = new URL(req.url, 'https://example.com/');
let candidateUrl = '';
let secondCandidateUrl = '';
for ( const pathMatch in pathMatches ) {
if ( pathMatches[pathMatch](requestUrl.pathname) ) {
// If we get an exact match, we don't need to process further.
return next();
} else if ( requestUrl.pathname.endsWith('/') && patchMatches[pathMatch](`${requestUrl.pathname}index`) ) {
} else if ( requestUrl.pathname.endsWith('/') && pathMatches[pathMatch](`${requestUrl.pathname}index`) ) {
// If we end with a /, and the index path matches, lets do the index path, but prioritize the non-index path.
let secondRequestUrl = new URL(requestUrl);
const secondRequestUrl = new URL(requestUrl);
secondRequestUrl.pathname = `${requestUrl.pathname}index`;
candidateUrl = secondRequestUrl.toString().substring(19);
} else if ( pathName[pathMatch](`${requestUrl.pathname}/index`) ) {
} else if ( pathMatches[pathMatch](`${requestUrl.pathname}/index`) ) {
// If we don't end with a /, and the /index path matches, lets do the /index path, but prioritize paths checked previously.
let secondRequestUrl = new URL(requestUrl);
const secondRequestUrl = new URL(requestUrl);
secondRequestUrl.pathname = `${requestUrl.pathname}/index`;
secondCandidateUrl = secondRequestUrl.toString().substring(19);
}
}
if ( candidateUrl !== "" ) {
if ( candidateUrl !== '' ) {
req.url = candidateUrl;
console.log(candidateUrl);
return next();
}
if ( secondCandidateUrl !== "" ) {
if ( secondCandidateUrl !== '' ) {
req.url = secondCandidateUrl;
return next();
}
return next();
});
for ( let routeScript in routes ) {
let route = routes[routeScript].replace(/\.js$/, "");
pathMatches.push(createPathMatch(route));
let routeObj = require(`./routes/${route}`);
} );
for ( const routeScript in routes ) {
const route = routes[routeScript].replace(/\.js$/, '');
console.log(route);
pathMatches.push( createPathMatch(`/${route}`));
const routeObj = require(`./routes/${route}`);
if ( routeObj.get ) {
app.get(`/${route}`, routeObj.get);
}
}
app.listen(process.env.PORT || 3000);
})();
})();

1680
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -16,5 +16,9 @@
"express": "^4.18.2",
"glob": "^9.3.0",
"path-to-regexp": "^6.2.1"
},
"devDependencies": {
"eslint": "^8.36.0",
"license-checker": "^25.0.1"
}
}