daton/lib/src/http/response/JSONResponseFactory.ts

18 lines
509 B
TypeScript
Raw Normal View History

import ResponseFactory from './ResponseFactory.ts'
import {Request} from '../Request.ts'
export default class JSONResponseFactory extends ResponseFactory {
constructor(
public readonly value: any
) {
super()
}
public async write(request: Request): Promise<Request> {
request = await super.write(request)
request.response.headers.set('Content-Type', 'application/json')
request.response.body = JSON.stringify(this.value)
return request
}
}