mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 14:06:40 -04:00
more error handling
This commit is contained in:
@ -7,10 +7,35 @@ import * as Sentry from "@sentry/nextjs";
|
||||
import * as config from "../../lib/config";
|
||||
|
||||
const ContactSchema = v.object({
|
||||
name: v.pipe(v.string(), v.nonEmpty("Your name is required.")),
|
||||
email: v.pipe(v.string(), v.nonEmpty("Your email address is required."), v.email("Invalid email address.")),
|
||||
message: v.pipe(v.string(), v.nonEmpty("A message is required.")),
|
||||
"cf-turnstile-response": v.pipe(v.string(), v.nonEmpty("Just do the stinkin CAPTCHA! 🤖")),
|
||||
// TODO: replace duplicate error messages with v.message() when released. see:
|
||||
// https://valibot.dev/api/message/
|
||||
// https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/message/message.ts
|
||||
name: v.pipe(v.string("Your name is required."), v.trim(), v.nonEmpty("Your name is required.")),
|
||||
email: v.pipe(
|
||||
v.string("Your email address is required."),
|
||||
v.trim(),
|
||||
v.nonEmpty("Your email address is required."),
|
||||
v.email("Invalid email address.")
|
||||
),
|
||||
message: v.pipe(
|
||||
v.string("A message is required."),
|
||||
v.trim(),
|
||||
v.nonEmpty("A message is required."),
|
||||
v.minLength(10, "Your message must be at least 10 characters.")
|
||||
),
|
||||
"cf-turnstile-response": v.pipe(
|
||||
// token wasn't submitted at _all_, most likely a direct POST request by a spam bot
|
||||
v.string("Shoo, bot."),
|
||||
// form submitted properly but token was missing, might be a forgetful human
|
||||
v.nonEmpty("Just do the stinkin CAPTCHA, human! 🤖"),
|
||||
// very rudimentary length check based on Cloudflare's docs
|
||||
// https://developers.cloudflare.com/turnstile/troubleshooting/testing/
|
||||
v.minLength("XXXX.DUMMY.TOKEN.XXXX".length),
|
||||
// "A Turnstile token can have up to 2048 characters."
|
||||
// https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
|
||||
v.maxLength(2048),
|
||||
v.readonly()
|
||||
),
|
||||
});
|
||||
|
||||
export type ContactInput = v.InferInput<typeof ContactSchema>;
|
||||
|
@ -28,7 +28,7 @@ const Page = () => {
|
||||
</p>
|
||||
<p>
|
||||
🔐 You can grab my public key here:{" "}
|
||||
<Link href="/pubkey.asc" title="My Public PGP Key" rel="pgpkey authn" openInNewTab>
|
||||
<Link href="https://jrvs.io/pgp" title="My Public Key">
|
||||
<code style={{ fontSize: "0.925em", letterSpacing: "0.075em", wordSpacing: "-0.3em" }}>
|
||||
6BF3 79D3 6F67 1480 2B0C 9CF2 51E6 9A39
|
||||
</code>
|
||||
|
@ -23,6 +23,8 @@ const HitCounter = async ({ slug }: { slug: string }) => {
|
||||
);
|
||||
} catch (error) {
|
||||
Sentry.captureException(error);
|
||||
|
||||
return <span title="Error getting views! :(">?</span>;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -258,13 +258,12 @@ const Page = () => {
|
||||
</Link>{" "}
|
||||
<sup>
|
||||
<Link
|
||||
href="/pubkey.asc"
|
||||
rel="pgpkey authn"
|
||||
href="https://jrvs.io/pgp"
|
||||
rel="pgpkey"
|
||||
title="My Public Key"
|
||||
lightColor="#757575"
|
||||
darkColor="#959595"
|
||||
plain
|
||||
openInNewTab
|
||||
>
|
||||
<LockIcon size="1.25em" style={{ verticalAlign: "-0.25em" }} />{" "}
|
||||
<span
|
||||
|
@ -10,8 +10,6 @@ import type { User, Repository } from "@octokit/graphql-schema";
|
||||
|
||||
import styles from "./page.module.css";
|
||||
|
||||
export const revalidate = 600; // 10 minutes
|
||||
|
||||
export const metadata = addMetadata({
|
||||
title: "Projects",
|
||||
description: `Most-starred repositories by @${config.authorSocial?.github} on GitHub`,
|
||||
@ -80,6 +78,20 @@ const getRepos = async (): Promise<Project[] | null> => {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
authorization: `token ${process.env.GITHUB_TOKEN}`,
|
||||
},
|
||||
request: {
|
||||
// override fetch() to use next's extension to cache the response
|
||||
// https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options
|
||||
fetch: (url: string | URL | Request, options?: RequestInit) => {
|
||||
return fetch(url, {
|
||||
...options,
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
// 10 minutes
|
||||
revalidate: 600,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -7,7 +7,7 @@ const robots = (): MetadataRoute.Robots => ({
|
||||
rules: [
|
||||
{
|
||||
userAgent: "*",
|
||||
disallow: ["/_stream/", "/api/", "/pubkey.asc", "/404", "/500"],
|
||||
disallow: ["/_stream/", "/api/", "/404", "/500"],
|
||||
},
|
||||
],
|
||||
sitemap: `${BASE_URL}/sitemap.xml`,
|
||||
|
Reference in New Issue
Block a user