Spaces:
Sleeping
Sleeping
import Koa from "koa"; | |
import bodyParser from "koa-bodyparser"; | |
const app = new Koa(); | |
app.use(bodyParser()); | |
app.use(async (ctx) => { | |
if (ctx.request.method === "POST") { | |
const { cookie } = ctx.request.body as { cookie: string }; | |
ctx.cookies.set("cookie-none", cookie, { secure: true, sameSite: "none" }); | |
ctx.cookies.set("cookie-lax", cookie, { secure: true, sameSite: "lax" }); | |
ctx.redirect( "/"); | |
} else { | |
ctx.body = `<html> | |
<body> | |
<pre>${JSON.stringify(Object.fromEntries(Object.entries(ctx.request.headers)), null, 2)}</pre> | |
<p>Cookie SameSite=None: ${ctx.cookies.get("cookie-none")?.replace(/</g, '$lt;')}</p> | |
<p>Cookie SameSite=Lax: ${ctx.cookies.get("cookie-lax")?.replace(/</g, '$lt;')}</p> | |
<form method="POST"> | |
<label>Cookie value<br> | |
<input type="text" name="cookie" /> | |
</label> | |
<button>Send</button> | |
</form> | |
</body> | |
</html>`; | |
} | |
}); | |
app.listen(7860); | |