Created
September 21, 2016 18:32
-
-
Save ybootin/29ee8b2bf85f835e2e9a9387169e451b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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