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.
lib/src/http/response/DehydratedStateResponseFact...

21 lines
702 B

import {ResponseFactory} from "./ResponseFactory"
import {Rehydratable} from "@extollo/util"
import {Request} from "../lifecycle/Request";
export function dehydrate(value: Rehydratable): DehydratedStateResponseFactory {
return new DehydratedStateResponseFactory(value)
}
export class DehydratedStateResponseFactory extends ResponseFactory {
constructor(
public readonly rehydratable: Rehydratable
) { super() }
public async write(request: Request) {
request = await super.write(request)
request.response.body = JSON.stringify(this.rehydratable.dehydrate())
request.response.setHeader('Content-Type', 'application/json')
return request
}
}