test-req / server.ts
coyotte508
⚗️ Try cookie settings
eed224b
raw
history blame
665 Bytes
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", cookie);
ctx.redirect( "/");
} else {
ctx.body = `<html>
<body>
<pre>${JSON.stringify(Object.fromEntries(Object.entries(ctx.request.headers)), null, 2)}</pre>
<form method="POST">
<label>Cookie value<br>
<input type="text" name="cookie />
</label>
<button>Send</button>
</form>
</body>
</html>`;
}
});
app.listen(7860);