Skip to content

Commit

Permalink
Merge pull request #1464 from kethinov/0.23.2
Browse files Browse the repository at this point in the history
0.23.2
  • Loading branch information
kethinov authored Sep 11, 2024
2 parents 6552bfd + 88a3e64 commit 41e9709
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 407 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

- Put your changes here...

## 0.23.2

- Removed `toobusy` feature since it is temperamental and the dependency is no longer maintained.
- Refactored internal `wildcardMatch` to use `minimatch` under the hood.
- Replaced `html-minifier` with `html-minifier-terser` since `html-minifier-terser` is better-maintained.
- Updated various dependencies.

## 0.23.1

- Added feature that scans the router stack to move the 404 route (the `*` route) to the end of the stack every time a new route is added, even if the route is added at runtime so that you can dynamically add routes while the app is running.
Expand Down
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,6 @@ Resolves to:
- Default: *[Number]* `30000` (30 seconds).
- `toobusy`: Parameters to pass to the [node-toobusy](https://github.com/STRML/node-toobusy) module.
- `maxLagPerRequest`: *[Number]* Maximum amount of time (in milliseconds) a given request is allowed to take before being interrupted with a [503 error](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors).
- `lagCheckInterval`: *[Number]* Interval (in milliseconds) for checking event loop lag in milliseconds.
- Default: *[Object]*
```json
{
"maxLagPerRequest": 70,
"lagCheckInterval": 500
}
```
### App behavior parameters
- `appDir`: Root directory of your application.
Expand Down Expand Up @@ -685,7 +670,7 @@ Resolves to:
- Default: *[Boolean]* `true`.
- `minifyOptions`: *[Object]* Parameters to supply to [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s API.
- `minifyOptions`: *[Object]* Parameters to supply to [html-minifier](https://github.com/terser/html-minifier-terser#options-quick-reference)'s API.
- Uses the params you set in `html.minifier.options` if empty.
Expand Down
5 changes: 0 additions & 5 deletions lib/defaults/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
"formidable": {
"multiples": true
},
"toobusy": {
"enable": true,
"maxLagPerRequest": 70,
"lagCheckInterval": 500
},
"helmet": {},
"csrfProtection": true,
"bodyParser": {
Expand Down
10 changes: 5 additions & 5 deletions lib/htmlMinifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = function (app) {
const params = app.get('params').html.minifier
const options = params.options
const minify = require('html-minifier').minify
const minify = require('html-minifier-terser').minify

// check that HTML minifier is enabled and minify is true
if (app.get('params').minify && params.enable) {
Expand All @@ -24,12 +24,12 @@ module.exports = function (app) {
if (!exception) {
res.render = function (view, opts, callback) {
if (callback) {
renderer.call(this, view, opts, (err, html) => {
callback(err, minify(html, options))
renderer.call(this, view, opts, async (err, html) => {
callback(err, await minify(html, options))
})
} else {
renderer.call(this, view, opts, (err, html) => {
res.send(err || minify(html, options))
renderer.call(this, view, opts, async (err, html) => {
res.send(err || await minify(html, options))
})
}
}
Expand Down
19 changes: 0 additions & 19 deletions lib/mapRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require('@colors/colors')
const fs = require('fs-extra')
const path = require('path')
const klawSync = require('klaw-sync')
const toobusy = require('toobusy-js')

module.exports = app => {
const express = app.get('express')
Expand Down Expand Up @@ -46,24 +45,6 @@ module.exports = app => {
require('../defaultErrorPages/controllers/disableValidator')(app)
}

if (params.toobusy.enable) {
// define maximum number of miliseconds to wait for a given request to finish
toobusy.maxLag(params.toobusy.maxLagPerRequest)

// define interval in miliseconds to check for event loop lag
toobusy.interval(params.toobusy.lagCheckInterval)

// serve 503 page if the process is too busy
app.use((req, res, next) => {
if (toobusy()) {
logger.warn('Request failed because server is too busy.')
require(params.errorPages.serviceUnavailable)(app, req, res)
} else {
next()
}
})
}

// bind user-defined middleware which fires just before executing the controller if supplied
if (params.onReqBeforeRoute && typeof params.onReqBeforeRoute === 'function') {
app.use(params.onReqBeforeRoute)
Expand Down
4 changes: 2 additions & 2 deletions lib/preprocessStaticPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async (app, callback) => {
const appName = app.get('appName')
const htmlPath = app.get('htmlPath')
const htmlRenderedOutput = app.get('htmlRenderedOutput')
const htmlMinifier = require('html-minifier').minify
const htmlMinifier = require('html-minifier-terser').minify
const expressValidator = require('express-html-validator')(params.htmlValidator)
const minifyOptions = app.get('params').html.minifier.options
const logger = app.get('logger')
Expand Down Expand Up @@ -89,7 +89,7 @@ module.exports = async (app, callback) => {

// minify the html if minification is enabled
if (params.minify && params.html.minifier.enable) {
newHtml = htmlMinifier(newHtml, minifyOptions)
newHtml = await htmlMinifier(newHtml, minifyOptions)
}

// validate the html if the validator is enabled
Expand Down
19 changes: 0 additions & 19 deletions lib/scripts/configAuditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,25 +545,6 @@ function configAudit (appDir) {
}
break
}
case 'toobusy': {
checkTypes(userParam, key, ['object'])
const busyParam = userParam || {}
for (const busyKey of Object.keys(busyParam)) {
keyStack.push(busyKey)
switch (busyKey) {
case 'maxLagPerRequest':
checkTypes(busyParam[busyKey], busyKey, ['number'])
break
case 'lagCheckInterval':
checkTypes(busyParam[busyKey], busyKey, ['number'])
break
default:
foundExtra(['rooseveltConfig', ...keyStack])
}
keyStack.pop(busyKey)
}
break
}
default:
foundExtra(['rooseveltConfig', ...keyStack])
}
Expand Down
11 changes: 0 additions & 11 deletions lib/sourceParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,6 @@ module.exports = (params, app, appSchema) => {
formidable: {
default: defaults.formidable
},
toobusy: {
maxLagPerRequest: {
default: defaults.toobusy.maxLagPerRequest
},
lagCheckInterval: {
default: defaults.toobusy.lagCheckInterval
},
enable: {
default: defaults.toobusy.enable
}
},
helmet: {
default: defaults.helmet
},
Expand Down
26 changes: 3 additions & 23 deletions lib/tools/wildcardMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,13 @@
*/

const path = require('path')
const { minimatch } = require('minimatch')

module.exports = (str, matchList) => {
if (typeof matchList === 'string') {
matchList = [matchList]
}
if (typeof matchList === 'string') matchList = [matchList]
for (let rule of matchList) {
rule = path.normalize(rule).replace(/\\/g, '/') // normalize windows; including normalizing the slashes

// for this solution to work on any string, no matter what characters it has
const escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1')

// "." => find a single character, except newline or line terminator
// ".*" => matches any string that contains zero or more characters
rule = rule.split('*').map(escapeRegex).join('.*')

// "^" => matches any string with the following at the beginning of it
// "$" => matches any string with that in front at the end of it
rule = '^' + rule + '$'

// create a regular expression object for matching string
const regex = new RegExp(rule)

// returns true if it finds a match, otherwise it returns false
if (regex.test(str)) {
return true
}
if (minimatch(str, rule)) return true
}

return false
}
6 changes: 3 additions & 3 deletions lib/viewsBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = app => {
const path = require('path')
const klaw = require('klaw-sync')
const gitignoreScanner = require('./tools/gitignoreScanner')
const htmlMinifier = require('html-minifier').minify
const htmlMinifier = require('html-minifier-terser').minify
const fsr = require('./tools/fsr')(app)
const logger = app.get('logger')
const appName = app.get('appName')
Expand Down Expand Up @@ -171,7 +171,7 @@ module.exports = app => {
fsr.writeFileSync(writePath, fileData, ['📝', `${appName} writing new JS file ${writePath}`.green])
}

function preprocess (file, name) {
async function preprocess (file, name) {
const { onClientViewsProcess } = app.get('params')

// if the onClientViewsProcess event is defined, pass the current file through it
Expand All @@ -181,7 +181,7 @@ module.exports = app => {

// minify the file if the option is turned on (and it is not a pug file since pug can't really be minified)
if (willMinifyTemplates && path.extname(name) !== 'pug' && file.length > 0) {
file = htmlMinifier(file, minifyOptions)
file = await htmlMinifier(file, minifyOptions)
}

return file
Expand Down
Loading

0 comments on commit 41e9709

Please sign in to comment.