Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Created January 29, 2025 02:52
Show Gist options
  • Save purplecabbage/c9c65246da00fade7ab89e78b8f380ba to your computer and use it in GitHub Desktop.
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
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