Skip to content

Instantly share code, notes, and snippets.

@steren
Last active September 24, 2018 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steren/a45d71e3dc5fd54815ec971e7353d3ec to your computer and use it in GitHub Desktop.
Save steren/a45d71e3dc5fd54815ec971e7353d3ec to your computer and use it in GitHub Desktop.
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