git.iko.soy/rowtype-yoga/purescript-yoga-bun-yoga
on main help sign in
41 lines 1.5 kB history raw
1export const serveImpl = (options) => {
2 const server = Bun.serve(options);
3 return {
4 stopForce: () => server.stop(true),
5 stopGraceful: () => server.stop(false),
6 upgrade: (req) => () => server.upgrade(req),
7 port: server.port
8 };
9};
11export const wsDataImpl = (ws) => ws.data;
12export const setWsDataImpl = (ws, data) => { ws.data = data; };
14// String/text Response
15export const stringResponseImpl = (body, stuff) => new Response(body, stuff);
17// JSON Response
18export const jsonResponseImpl = (body, stuff) => Response.json(body, stuff);
20// Empty Response (for 204 No Content, etc.)
21export const emptyResponseImpl = (stuff) => new Response(null, stuff);
23// Response with ArrayBuffer
24export const arrayBufferResponseImpl = (buffer, stuff) => new Response(buffer, stuff);
26// Static Response constructors
27export const responseRedirectImpl = (url, status) => Response.redirect(url, status);
29export const responseErrorImpl = () => Response.error();
31// Response cloning
32export const cloneResponseImpl = (response) => response.clone();
34// URL search param (pure: URL constructor + searchParams.get)
35export const searchParamImpl = (url) => (name) => new URL(url).searchParams.get(name);
37// Request header (method call, needs .bind or direct call)
38export const requestHeaderImpl = (req) => (name) => req.headers.get(name);
40// Request body as text (returns Promise wrapped in Effect thunk)
41export const requestTextImpl = (req) => () => req.text();