Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Created January 29, 2025 02:52
Show Gist options
  • Select an option

  • Save purplecabbage/c9c65246da00fade7ab89e78b8f380ba to your computer and use it in GitHub Desktop.

Select an option

Save purplecabbage/c9c65246da00fade7ab89e78b8f380ba to your computer and use it in GitHub Desktop.

Revisions

  1. purplecabbage created this gist Jan 29, 2025.
    23 changes: 23 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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