🍪 Cookie for prismy.
npm i prismy-cookie
import {
prismy,
res,
createUrlEncodedBodySelector,
methodSelector,
contextSelector,
Context
} from 'prismy'
import {
createCookiesSelector,
ParsedCookies,
appendCookie
} from 'prismy-cookie'
const urlEncodedBodySelector = createUrlEncodedBodySelector()
const cookiesSelector = createCookiesSelector()
const handler = prismy(
[methodSelector, cookiesSelector, contextSelector],
async (method, cookies, context) => {
if (method === 'POST') {
const { message } = await urlEncodedBodySelector(context)
return appendCookie(res('OK!'), ['message', message as string])
}
return res(cookies.message)
}
)
export default prismy(handler)
MIT