Skip to content

Instantly share code, notes, and snippets.

@donaldgray
Created October 3, 2019 08:45
Show Gist options
  • Save donaldgray/e39220fe57c1258b8498dc3746475352 to your computer and use it in GitHub Desktop.
Save donaldgray/e39220fe57c1258b8498dc3746475352 to your computer and use it in GitHub Desktop.
Handler for testing RESTful svc
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
console.log(`${ctx.method} ${ctx.url}`);
const responseCode = ctx.url.startsWith('/') ? ctx.url.substring(1) : 200;
const delay = ctx.response.get('X-Delay-Ms');
if (delay) {
setTimeout(() => {
console.debug('done...');
ctx.res.statusCode = responseCode;
}, 15000);
}
});
app.listen(3000);
// const express = require('express');
// const app = express();
// let count = 0;
// app.get('*', (req, res) => {
// const currCount = count++;
// console.debug(`received ${req.url} (${currCount})...`);
// if (req.url.indexOf('ABC123') > -1) {
// console.debug(`done (${currCount})...`);
// res.end('done');
// }
// setTimeout(() => {
// console.debug(`done (${currCount})...`);
// res.end('done');
// }, 15000);
// });
// app.listen(3001, err => {
// if (err) throw err;
// console.log('Ready on port', 3001);
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment