ratelimiter-distil-router
Version:
SHIELD Rate Limiter DISTIL router middleware for Web Apps
51 lines (41 loc) • 1.98 kB
JavaScript
/**
* Copyright (c) 2019 eBay Inc.
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
**/
let express = require('express');
let blockPage = require('./pages/block/index.js');
let errorPage = require('./pages/error/index.js');
let captchaDistilPage = require('./pages/captcha-distil/index.js');
let captchaShieldPage = require('./pages/captcha-shield/index.js');
/**
* Express Middleware for hooking URL and receiving client payload.
* Calls Custom hook registered in middleware.
**/
function shieldCaptchaMiddleware() {
let shieldCaptchaApp = express();
shieldCaptchaApp.get('/block', function (req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
blockPage.load(req).then(data => res.status(200).send(data)).catch(error => res.status(200).send(error));
})
shieldCaptchaApp.get('/captcha_shield', function (req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
captchaShieldPage.load(req).then(data => res.status(200).send(data)).catch(error => res.status(200).send(error));
})
shieldCaptchaApp.get('/captcha_distil', function (req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
captchaDistilPage.load(req).then(data => res.status(200).send(data)).catch(error => res.status(200).send(error));
})
shieldCaptchaApp.get('/error', function (req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
errorPage.load(req).then(data => res.status(200).send(data)).catch(error => res.status(200).send(error));
})
shieldCaptchaApp.get('/dummy', function (req, res, next) {
res.send('<html><body>DUMMY</body></html>')
})
return shieldCaptchaApp;
}
module.exports = shieldCaptchaMiddleware;