Skip to content

Commit

Permalink
fix: ssr & crypto use BodyInit instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
sejori committed Mar 26, 2023
1 parent 212b098 commit e41c9e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion handlers/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Handler, HandlerOptions } from "../types.ts"
import { Crypto } from "../utils/Crypto.ts"
import { mergeHeaders } from "../utils/helpers.ts"

export type Render = (ctx: RequestContext) => string | Promise<string>
export type Render = (ctx: RequestContext) => BodyInit | Promise<BodyInit>
export interface ssrHandlerOptions extends HandlerOptions {
crypto?: Crypto
}
Expand Down
5 changes: 3 additions & 2 deletions utils/Crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export class Crypto {
* @param contents: string
* @returns hashHex: string
*/
async hash(contents: string): Promise<string> {
const hashBuffer = await crypto.subtle.digest(this.algData.hash, encoder.encode(contents))
async hash(contents: BodyInit): Promise<string> {
const temp = new Response(contents) // how to array buffer all the things
const hashBuffer = await crypto.subtle.digest(this.algData.hash, await temp.arrayBuffer())
return encodeB64(hashBuffer)
}

Expand Down

0 comments on commit e41c9e0

Please sign in to comment.