Просмотр исходного кода

Need to upgrade http-errors for growi

hakumizuki 4 лет назад
Родитель
Сommit
c199db3696

+ 1 - 0
packages/app/package.json

@@ -57,6 +57,7 @@
     "growi-plugin-lsx": "^4.0.3",
     "growi-plugin-pukiwiki-like-linker": "^3.1.0",
     "helmet": "^3.13.0",
+    "http-errors": "^1.8.0",
     "i18next": "^20.3.2",
     "i18next-express-middleware": "^2.0.0",
     "i18next-node-fs-backend": "^2.1.0",

+ 0 - 1
packages/slack/package.json

@@ -15,7 +15,6 @@
     "test:lint:fix": "eslint src --ext .ts --fix"
   },
   "dependencies": {
-    "@types/http-errors": "^1.8.0",
     "axios": "^0.21.1",
     "browser-bunyan": "^1.6.3",
     "bunyan": "^1.8.15",

+ 0 - 5
src/server/crowi/express-init.js

@@ -1,5 +1,3 @@
-const httpErrorHandler = require('../middlewares/http-error-handler');
-
 
 module.exports = function(crowi, app) {
   const debug = require('debug')('growi:crowi:express-init');
@@ -112,9 +110,6 @@ module.exports = function(crowi, app) {
     sessionMiddleware(req, res, next);
   });
 
-  // http-error-handler
-  app.use(httpErrorHandler);
-
   // passport
   debug('initialize Passport');
   app.use(passport.initialize());

+ 12 - 0
src/server/crowi/index.js

@@ -13,6 +13,7 @@ const mongoose = require('mongoose');
 const models = require('../models');
 
 const PluginService = require('../plugins/plugin.service');
+const httpErrorHandler = require('../middlewares/http-error-handler');
 
 const sep = path.sep;
 
@@ -451,6 +452,9 @@ Crowi.prototype.start = async function() {
   // setup Express Routes
   this.setupRoutesAtLast();
 
+  // setup Global Error Handlers
+  this.setupGlobalErrorHandlers();
+
   return serverListening;
 };
 
@@ -486,6 +490,14 @@ Crowi.prototype.setupRoutesAtLast = function() {
   require('../routes')(this, this.express);
 };
 
+/**
+ * setup global error handlers
+ * !! this must be after the Routes setup !!
+ */
+Crowi.prototype.setupGlobalErrorHandlers = function() {
+  this.express.use(httpErrorHandler);
+};
+
 /**
  * require API for plugins
  *

+ 1 - 2
src/server/middlewares/http-error-handler.js

@@ -1,5 +1,4 @@
-
-const { isHttpError } = require('http-errors');
+const { isHttpError } = require('../../../node_modules/http-errors');
 
 module.exports = (err, req, res, next) => {
   // handle if the err is a HttpError instance

+ 1 - 0
src/server/service/app.js

@@ -113,6 +113,7 @@ class AppService extends S2sMessageHandlable {
   async setupAfterInstall() {
     this.crowi.pluginService.autoDetectAndLoadPlugins();
     this.crowi.setupRoutesAtLast();
+    this.crowi.setupGlobalErrorHandlers();
 
     // remove message handler
     const { s2sMessagingService } = this;

+ 0 - 5
yarn.lock

@@ -3010,11 +3010,6 @@
     "@types/qs" "*"
     "@types/serve-static" "*"
 
-"@types/http-errors@^1.8.0":
-  version "1.8.0"
-  resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-1.8.0.tgz#682477dbbbd07cd032731cb3b0e7eaee3d026b69"
-  integrity sha512-2aoSC4UUbHDj2uCsCxcG/vRMXey/m17bC7UwitVm5hn22nI8O8Y9iDpA76Orc+DWkQ4zZrOKEshCqR/jSuXAHA==
-
 "@types/is-stream@^1.1.0":
   version "1.1.0"
   resolved "https://registry.yarnpkg.com/@types/is-stream/-/is-stream-1.1.0.tgz#b84d7bb207a210f2af9bed431dc0fbe9c4143be1"