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/TemporaryRedirectResponseFa...

22 lines
694 B

import {ResponseFactory} from "./ResponseFactory";
import {HTTPStatus} from "@extollo/util";
import {Request} from "../lifecycle/Request";
export function redirect(destination: string): TemporaryRedirectResponseFactory {
return new TemporaryRedirectResponseFactory(destination)
}
export class TemporaryRedirectResponseFactory extends ResponseFactory {
protected targetStatus: HTTPStatus = HTTPStatus.TEMPORARY_REDIRECT
constructor(
public readonly destination: string
) { super() }
public async write(request: Request) {
request = await super.write(request)
request.response.setHeader('Location', this.destination)
return request
}
}