Skip to content

Instantly share code, notes, and snippets.

@danieljpgo
Last active September 2, 2022 02:58
Show Gist options
  • Save danieljpgo/cfccdd477e0397688f327358b6c10d71 to your computer and use it in GitHub Desktop.
Save danieljpgo/cfccdd477e0397688f327358b6c10d71 to your computer and use it in GitHub Desktop.
/lib/remix.ts
/**
* Create a response with a permanently redirect using `301` as status code.
*/
export function redirectPermanently(
url: string,
init?: Omit<ResponseInit, "status">
) {
return redirect(url, { ...init, status: 301 });
}
/**
* Create a response with a Not Found error using `404` as status code.
*/
export function notFound(init?: Omit<ResponseInit, "status">) {
return json("Not Found", { ...init, status: 404 });
}
/**
* Create a response receiving a JSON object with the status code 400.
*/
export function badRequest<Data = unknown>(
data: Data,
init?: Omit<ResponseInit, "status">
) {
return json<Data>(data, { ...init, status: 400 });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment