-
-
Save joshwash/18c1e26cd6530511199fc0076e03ef66 to your computer and use it in GitHub Desktop.
cache check
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
let request = require('async-request') | |
let tough = require('tough-cookie') | |
const Cookie = tough.Cookie | |
const url = 'https://www.example.org/' | |
async function start(event, context) { | |
const response = await request(url, { | |
method: 'GET', | |
headers: { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0' | |
} | |
}); | |
let cookie = Cookie.parse(response.headers['set-cookie'].join('; ')) | |
if(response.statusCode !== 200) { | |
return { | |
statusCode: 500, | |
body: new Error('Did not recieve HTTP OK (200)') | |
} | |
} | |
if(!response.headers.hasOwnProperty('x-litespeed-cache')) { | |
return { | |
statusCode: 500, | |
body: new Error('Did not find litespeed cache header') | |
} | |
} | |
if(response.headers['x-litespeed-cache'] !== 'hit') { | |
// Try again using the cookie we just got | |
const r2 = await request(url, { | |
method: 'GET', | |
headers: { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0' | |
}, | |
cookieJar: cookie | |
}); | |
if(r2.headers['x-litespeed-cache'] !== 'hit') { | |
return { | |
statusCode: 500, | |
body: new Error('OLS Cache was not hit'), | |
b: r2.headers | |
} | |
} | |
} | |
return { | |
statusCode: 200, body: 'OK' | |
} | |
} | |
start().then(response => { | |
console.log(response) | |
}) | |
module.exports = 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
{ | |
"name": "serverstatus", | |
"version": "1.0.0", | |
"description": "Checks status of things", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"app": "node index.js" | |
}, | |
"author": "Josh", | |
"license": "ISC", | |
"dependencies": { | |
"async-request": "^1.2.0", | |
"tough-cookie": "^3.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment