Skip to content

Commit

Permalink
feat(serve)!: ctx.html takes string; ctx.render takes hypernode
Browse files Browse the repository at this point in the history
Signed-off-by: Muthu Kumar <[email protected]>
  • Loading branch information
MKRhere committed Feb 12, 2022
1 parent 2441f91 commit 4532501
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions serve/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export type Context<State = {}> = {
request: Request;
responded: boolean;
respond: (body?: Response | BodyInit | null, init?: ResponseInit) => Promise<void>;
html: (body: HyperNode, init?: ResponseInit) => Promise<void>;
html: (body: string, init?: ResponseInit) => Promise<void>;
render: (body: HyperNode, init?: ResponseInit) => Promise<void>;
state: State;
};

Expand Down Expand Up @@ -43,12 +44,15 @@ function Context(e: Deno.RequestEvent): Context {
html(body, init) {
const headers = new Headers(init?.headers);
headers.set("Content-Type", "text/html; charset=UTF-8");
return self.respond("<!DOCTYPE html>" + renderHTML(body), {
return self.respond(body, {
headers,
status: init?.status,
statusText: init?.statusText,
});
},
render(body, init) {
return self.html("<!DOCTYPE html>" + renderHTML(body), init);
},
state: {},
};

Expand Down

0 comments on commit 4532501

Please sign in to comment.