Files
lib/src/http/response/HTMLResponseFactory.ts
garrettmills 1d5056b753
All checks were successful
continuous-integration/drone/push Build is passing
Setup eslint and enforce rules
2021-06-02 22:36:25 -05:00

29 lines
762 B
TypeScript

import {ResponseFactory} from './ResponseFactory'
import {Request} from '../lifecycle/Request'
/**
* Helper function that creates a new HTMLResponseFactory.
* @param value
*/
export function html(value: string): HTMLResponseFactory {
return new HTMLResponseFactory(value)
}
/**
* Response factory that writes a string to the response as HTML.
*/
export class HTMLResponseFactory extends ResponseFactory {
constructor(
public readonly value: string,
) {
super()
}
public async write(request: Request): Promise<Request> {
request = await super.write(request)
request.response.setHeader('Content-Type', 'text/html; charset=utf-8')
request.response.body = this.value
return request
}
}