import {ResponseFactory} from './ResponseFactory' import {HTTPStatus} from '../../util' import {Request} from '../lifecycle/Request' /** * Helper function to create a new TemporaryRedirectResponseFactory to the given destination. * @param destination */ export function temporary(destination: string): TemporaryRedirectResponseFactory { return new TemporaryRedirectResponseFactory(destination) } /** * Response factory that sends an HTTP redirect to the given destination. */ export class TemporaryRedirectResponseFactory extends ResponseFactory { protected targetStatus: HTTPStatus = HTTPStatus.TEMPORARY_REDIRECT constructor( /** THe URL where the client should redirect to. */ public readonly destination: string, ) { super() } public async write(request: Request): Promise { request = await super.write(request) request.response.setHeader('Location', this.destination) return request } }