Created
January 29, 2025 02:52
-
-
Save purplecabbage/c9c65246da00fade7ab89e78b8f380ba to your computer and use it in GitHub Desktop.
Action that returns html - sets an http cookie and increments it when it sees it
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
async function main (params) { | |
console.log('params?.__ow_headers?.cookie =', params?.__ow_headers?.cookie) | |
let newValue = params?.__ow_headers?.cookie?.split('=')[1] || 0 | |
return { | |
statusCode:200, | |
headers: { 'Content-Type': 'text/html', | |
'set-cookie': `mycookie=${parseInt(newValue) + 1}; Secure; HttpOnly; SameSite=Strict` | |
}, | |
body: | |
`<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Example</title> | |
</head> | |
<body> | |
<h1>Hello, world!</h1> | |
<pre>${JSON.stringify(params, null, 2)}</pre> | |
</body> | |
</html>` | |
} | |
} | |
exports.main = main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment