You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
578 B
20 lines
578 B
3 years ago
|
import {ResponseFactory} from "./ResponseFactory";
|
||
|
import {Request} from "../lifecycle/Request";
|
||
|
|
||
|
export function json(value: any): JSONResponseFactory {
|
||
|
return new JSONResponseFactory(value)
|
||
|
}
|
||
|
|
||
|
export class JSONResponseFactory extends ResponseFactory {
|
||
|
constructor(
|
||
|
public readonly value: any
|
||
|
) { super() }
|
||
|
|
||
|
public async write(request: Request) {
|
||
|
request = await super.write(request)
|
||
|
request.response.setHeader('Content-Type', 'application/json')
|
||
|
request.response.body = JSON.stringify(this.value)
|
||
|
return request
|
||
|
}
|
||
|
}
|