binhend 1.1.6 → 1.1.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.js +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/server.js CHANGED
@@ -8,6 +8,18 @@ function Server(options) {
8
8
  const WEB_DIRECTORY = options.web;
9
9
  const CORS = options.cors;
10
10
 
11
+ // Handle error of ExpressJS: URIError: Failed to decode param
12
+ // Error happens when add wrong '%' (e.i. invalid encoded URI component) into the request URL
13
+ server.use(function(req, res, next) {
14
+ try {
15
+ decodeURIComponent(req.path);
16
+ next();
17
+ }
18
+ catch(e) {
19
+ res.redirect('/');
20
+ }
21
+ });
22
+
11
23
  if (CORS instanceof Function) {
12
24
  server.use(CORS);
13
25
  }