Skip to content

Instantly share code, notes, and snippets.

@Romanmir
Forked from jamesbiederbeck/Responder.js
Created March 3, 2020 22:46
Show Gist options
  • Save Romanmir/9894323d8044a2aebe1d0964c14ea3f4 to your computer and use it in GitHub Desktop.
Save Romanmir/9894323d8044a2aebe1d0964c14ea3f4 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
const express = require('express')
const app = express()
const port = 3000
const response_text = 'Hello World!\nAlso more text here for testing\nAlso different text for lookbehind\n'
app.all("*", function (req, resp, next) {
console.log("Got request!");
next();
});
app.get('/', (req, res) => res.send(response_text))
app.get('/timeout/:time', function(req, res) {
timeout = req.param("time");
console.log(`Per request, waiting ${timeout}`)
setTimeout(function(){
console.log("No more lollygagging");
res.send(response_text);
}, timeout)
;
});
app.get('/empty/', function(req, res) {
console.log(`Per request, ending connection prematurely`);
res.end()
});
app.listen(port, () => console.log(`Listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment