mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added a server testmode to help test behaviour
- A simple way to test behaviours without having to do complex interactions to e.g. generate errors or slow requests - Makes it easier to test the new shutdown behaviour, among other things
This commit is contained in:
parent
a96f434163
commit
b0512f2c25
3 changed files with 36 additions and 0 deletions
|
@ -128,6 +128,13 @@ class GhostServer {
|
|||
process
|
||||
.removeAllListeners('SIGINT').on('SIGINT', shutdown)
|
||||
.removeAllListeners('SIGTERM').on('SIGTERM', shutdown);
|
||||
|
||||
if (config.get('server:testmode')) {
|
||||
// Debug code
|
||||
setInterval(() => self.httpServer.getConnections(
|
||||
(err, connections) => logging.warn(`${connections} connections currently open`)
|
||||
), 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const debug = require('ghost-ignition').debug('web:api:default:app');
|
||||
const config = require('../../../shared/config');
|
||||
const express = require('../../../shared/express');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const errorHandler = require('../shared/middlewares/error-handler');
|
||||
|
@ -7,6 +8,10 @@ module.exports = function setupApiApp() {
|
|||
debug('Parent API setup start');
|
||||
const apiApp = express('api');
|
||||
|
||||
if (config.get('server:testmode')) {
|
||||
apiApp.use(require('./testmode')());
|
||||
}
|
||||
|
||||
// Mount different API versions
|
||||
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app')());
|
||||
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app')());
|
||||
|
|
24
core/server/web/api/testmode.js
Normal file
24
core/server/web/api/testmode.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const logging = require('../../../shared/logging');
|
||||
const express = require('../../../shared/express');
|
||||
|
||||
/** A bunch of helper routes for testing purposes */
|
||||
module.exports = function testRoutes() {
|
||||
const router = express.Router('canary admin');
|
||||
|
||||
router.get('/500', (req, res) => res.sendStatus(500));
|
||||
router.get('/400', (req, res) => res.sendStatus(400));
|
||||
router.get('/404', (req, res) => res.sendStatus(404));
|
||||
router.get('/slow/:timeout', (req, res) => {
|
||||
if (!req.params || !req.params.timeout) {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
const timeout = req.params.timeout * 1000;
|
||||
logging.info('Begin Slow Request with timeout of', timeout);
|
||||
setTimeout(() => {
|
||||
logging.info('End Slow Request', timeout);
|
||||
res.sendStatus(200);
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
Loading…
Add table
Reference in a new issue