Last active
September 24, 2018 05:14
-
-
Save steren/a45d71e3dc5fd54815ec971e7353d3ec to your computer and use it in GitHub Desktop.
Function to generate traffic for a minute on a given URL
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
FROM node:8 | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
ENV NODE_ENV=production | |
RUN npm install --production | |
COPY . . | |
CMD [ "npm", "start" ] |
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
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(); | |
}; | |
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
{ | |
"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