Skip to content

Instantly share code, notes, and snippets.

@steren
Last active Sep 24, 2018
Embed
What would you like to do?
Function to generate traffic for a minute on a given URL
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
ENV NODE_ENV=production
RUN npm install --production
COPY . .
CMD [ "npm", "start" ]
const axios = require('axios');
/**
* Responds to any HTTP request.
*
* @param {!Object} req HTTP request context.
* @param {!Object} res HTTP response context.
*/
exports.hit = (req, res) => {
let url = req.query.url;
let iteration = 0;
let timer;
if(!url) {
return res.status(200).send('Please provide URL');
}
function callUrl() {
if(iteration < 60) {
console.log(`Hitting (${iteration}) ${url}`);
axios.get(url);
iteration++;
timer = setTimeout(callUrl, 1000);
} else {
console.log(`Done hitting ${url}`);
clearTimeout(timer);
res.status(200).send('done');
}
}
callUrl();
};
{
"name": "hit-url",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "func hit"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"function-to-app": "0.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment