Ghost/core/server/web/api/testmode.js
Hannah Wolfe b0512f2c25 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
2020-08-10 16:38:49 +01:00

25 lines
864 B
JavaScript

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;
};