-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ce9536
commit 5644f63
Showing
3 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
async rewrites() { | ||
return { | ||
fallback: [ | ||
{ | ||
source: "/:path*", | ||
destination: `/api/link/?slug=:path*` | ||
} | ||
] | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// the idea with all of the weird cache stuff is we don't ever have to worry about hitting airtable's rate limits | ||
// if i get a ton of traffic for some reason, while still being able to fetch new data from airtable every | ||
// once in a while so i don't have to rebuild the site every time i want to update shortened links like i did previously. | ||
// the other advantage of running redirects here instead of next.config.js is that i can add some basic/privacy-friendly | ||
// logs of what links were accessed when and where which wasn't an option previously. | ||
// also stale while revalidate is pretty pog, see https://vercel.com/docs/concepts/functions/edge-caching | ||
|
||
// idk how to handle 404s yet but that shouldn't be too painful i hope - if i return a 404 does it | ||
// serve the 404 page for me? then i can style that and make it all nice | ||
|
||
export default async (req, res) => { | ||
const ALLOWED_METHODS = ["GET", "HEAD"] | ||
if (!ALLOWED_METHODS.includes(req.method)) { | ||
return res.send("Only GET and HEAD methods are supported.") | ||
} | ||
|
||
if (req.cookies["_vercel_no_cache"] === 1 || req.query["?_vercel_no_cache"] === 1 || req.headers["Authorization"] || req.headers["Range"]) { | ||
return res.send("sorry, we must get that cash!") | ||
} | ||
|
||
// TODO: Airtable stuff | ||
|
||
res.setHeader("Cache-Control", "s-maxage=10, stale-while-revalidate") | ||
return res.redirect(308, "https://jasonaa.me") | ||
} |