Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// A simple webserver to simulate response delay on VAST call
var express = require('express');
var app = express();
var fs = require('fs')
// CORS
app.all('/', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Access-Control-Allow-Credentials', true);
next();
});
app.get('/:vast/:timeout?/:credential?', function(req, res) {
var vast = __dirname + '/' + decodeURIComponent(req.params.vast)
var timeout = req.params.timeout || 0
var credential = !!req.params.credential
timeout = typeof timeout === 'string' ? parseInt(timeout, 10) : timeout
console.log('wait for ' + timeout + 'ms to display content ' + vast)
setTimeout(function() {
try {
var stats = fs.statSync(vast)
var file = fs.readFileSync(vast)
} catch (e) {
var file = '<?xml version="1.0" encoding="UTF-8"?>\n<VAST></VAST>';
}
// if (credential) {
// res.header('Access-Control-Allow-Credentials', credential);
// }
res.setHeader('Content-Type', 'text/xml');
res.send(file)
res.end()
console.log('response sent !')
}, timeout)
})
app.listen(3000);
console.log('start request-timeout-mock at http://localhost:3000');
module.exports = {
'plugin:request-timeout-mock': ['type', app]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.