-
Notifications
You must be signed in to change notification settings - Fork 628
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
b5b139a
commit 514d834
Showing
6 changed files
with
120 additions
and
64 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
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,57 @@ | ||
import type {LoaderFunction} from 'remix' | ||
import * as dateFns from 'date-fns' | ||
import {getBlogMdxListItems} from '~/utils/mdx' | ||
import {getDomainUrl} from '~/utils/misc' | ||
|
||
export const loader: LoaderFunction = async ({request}) => { | ||
const posts = await getBlogMdxListItems({request}) | ||
|
||
const blogUrl = `${getDomainUrl(request)}/blog` | ||
|
||
const rss = ` | ||
<rss xmlns:blogChannel="${blogUrl}" version="2.0"> | ||
<channel> | ||
<title>Kent C. Dodds Blog</title> | ||
<link>${blogUrl}</link> | ||
<description>The Kent C. Dodds Blog</description> | ||
<language>en-us</language> | ||
<generator>Kody the Koala</generator> | ||
<ttl>40</ttl> | ||
${posts | ||
.map(post => | ||
` | ||
<item> | ||
<title>${cdata(post.frontmatter.title ?? 'Untitled Post')}</title> | ||
<description>${cdata( | ||
post.frontmatter.description ?? 'This post is... indescribable', | ||
)}</description> | ||
<pubDate>${dateFns.format( | ||
dateFns.add( | ||
post.frontmatter.date | ||
? dateFns.parseISO(post.frontmatter.date) | ||
: Date.now(), | ||
{minutes: new Date().getTimezoneOffset()}, | ||
), | ||
'yyyy-MM-ii', | ||
)}</pubDate> | ||
<link>${blogUrl}/${post.slug}</link> | ||
<guid>${blogUrl}/${post.slug}</guid> | ||
</item> | ||
`.trim(), | ||
) | ||
.join('\n')} | ||
</channel> | ||
</rss> | ||
`.trim() | ||
|
||
return new Response(rss, { | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
'Content-Length': String(Buffer.byteLength(rss)), | ||
}, | ||
}) | ||
} | ||
|
||
function cdata(s: string) { | ||
return `<![CDATA[${s}]]>` | ||
} |
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,13 @@ | ||
import type {LoaderFunction} from 'remix' | ||
import {getPostJson} from '~/utils/blog.server' | ||
|
||
export const loader: LoaderFunction = async ({request}) => { | ||
const data = await getPostJson(request) | ||
const string = JSON.stringify(data) | ||
return new Response(string, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': String(Buffer.byteLength(string)), | ||
}, | ||
}) | ||
} |
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,22 @@ | ||
import type {LoaderFunction} from 'remix' | ||
import {prismaRead} from '~/utils/prisma.server' | ||
import {getBlogReadRankings} from '~/utils/blog.server' | ||
|
||
export const loader: LoaderFunction = async ({request}) => { | ||
const host = | ||
request.headers.get('X-Forwarded-Host') ?? request.headers.get('host') | ||
|
||
try { | ||
await Promise.all([ | ||
prismaRead.user.count(), | ||
getBlogReadRankings({request}), | ||
fetch(`http://${host}`, {method: 'HEAD'}).then(r => { | ||
if (!r.ok) return Promise.reject(r) | ||
}), | ||
]) | ||
return new Response('OK') | ||
} catch (error: unknown) { | ||
console.log('healthcheck ❌', {error}) | ||
return new Response('ERROR', {status: 500}) | ||
} | ||
} |
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,13 @@ | ||
import type {LoaderFunction} from 'remix' | ||
import {json} from 'remix' | ||
import {getAllUserData} from '~/utils/prisma.server' | ||
import {requireUser} from '~/utils/session.server' | ||
import {getUserInfo} from '~/utils/user-info.server' | ||
|
||
export const loader: LoaderFunction = async ({request}) => { | ||
const user = await requireUser(request) | ||
|
||
const postgres = await getAllUserData(user.id) | ||
const cache = await getUserInfo(user, {request}) | ||
return json({postgres, cache}) | ||
} |
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,14 @@ | ||
import type {LoaderFunction} from 'remix' | ||
import {redisCache} from '~/utils/redis.server' | ||
import {commitShaKey as refreshCacheCommitShaKey} from './action/refresh-cache' | ||
|
||
export const loader: LoaderFunction = async () => { | ||
const shaInfo = await redisCache.get(refreshCacheCommitShaKey) | ||
const data = JSON.stringify(shaInfo) | ||
return new Response(data, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': String(Buffer.byteLength(data)), | ||
}, | ||
}) | ||
} |