-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from Aryan51203/main
Improvements to loading and CORS
- Loading branch information
Showing
7 changed files
with
184 additions
and
104 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 |
---|---|---|
@@ -1,34 +1,40 @@ | ||
/** @type {import('next').NextConfig} */ | ||
|
||
const cspValue = [ | ||
"default-src 'self'", | ||
"style-src 'self' 'unsafe-inline'", | ||
"frame-ancestors 'none'", | ||
"script-src 'self' 'unsafe-inline' 'unsafe-eval'", | ||
"img-src 'self' https://authjs.dev/ data:", // https://authjs.dev/ for images during the login flow | ||
"connect-src 'self' https://*.alchemy.com", // https://*.alchemy.com used by Witness | ||
] | ||
"default-src 'self'", | ||
"style-src 'self' 'unsafe-inline'", | ||
"frame-ancestors 'none'", | ||
"script-src 'self' 'unsafe-inline' 'unsafe-eval'", | ||
"img-src 'self' https://authjs.dev/ data:", // https://authjs.dev/ for images during the login flow | ||
"connect-src 'self' https://*.alchemy.com", // https://*.alchemy.com used by Witness | ||
]; | ||
|
||
const nextConfig = { | ||
async headers() { | ||
return [{ | ||
source: '/(.*)', | ||
headers: [ | ||
{ | ||
key: 'Content-Security-Policy', | ||
value: cspValue.join('; '), | ||
}, | ||
{ | ||
key: 'X-Content-Type-Options', | ||
value: 'nosniff', | ||
}, | ||
{ | ||
key: 'Strict-Transport-Security', | ||
value: 'max-age=63072000; includeSubDomains; preload' | ||
}, | ||
], | ||
}] | ||
}, | ||
} | ||
async headers() { | ||
return [ | ||
{ | ||
source: "/(.*)", | ||
headers: [ | ||
{ | ||
key: "Access-Control-Allow-Origin", | ||
value: "*", | ||
}, | ||
{ | ||
key: "Content-Security-Policy", | ||
value: cspValue.join("; "), | ||
}, | ||
{ | ||
key: "X-Content-Type-Options", | ||
value: "nosniff", | ||
}, | ||
{ | ||
key: "Strict-Transport-Security", | ||
value: "max-age=63072000; includeSubDomains; preload", | ||
}, | ||
], | ||
}, | ||
]; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
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,16 @@ | ||
import { Skeleton } from "@mui/material"; | ||
|
||
export default function Loading() { | ||
const skeletonCount = 4; // Number of Skeleton components to render | ||
const skeletons = Array.from({ length: skeletonCount }, (_, index) => ( | ||
<Skeleton | ||
key={index} | ||
sx={{ bgcolor: "grey.350" }} | ||
variant="rounded" | ||
width={"42rem"} | ||
height={"20rem"} | ||
style={{ margin: "1rem" }} | ||
/> | ||
)); | ||
return <div style={{ marginTop: "4rem" }}>{skeletons}</div>; | ||
} |
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 |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import { DomainSearchResults } from '@/components/DomainSearchResults'; | ||
import { SearchInput } from '@/components/SearchInput'; | ||
import { findKeysPaginated } from './actions'; | ||
import { parseDkimTagList } from '@/lib/utils'; | ||
"use client"; | ||
|
||
function dkimValueHasPrivateKey(dkimValue: string): boolean { | ||
return !!parseDkimTagList(dkimValue).p; | ||
} | ||
|
||
export default async function Home({ searchParams }: { | ||
searchParams: { [key: string]: string | string[] | undefined } | ||
}) { | ||
const domainQuery = searchParams?.domain?.toString(); | ||
let records = domainQuery ? await findKeysPaginated(domainQuery, null) : [] | ||
records = records.filter((record) => dkimValueHasPrivateKey(record.value)); | ||
|
||
return ( | ||
<div style={{ display: 'flex', minHeight: '100vh', flexDirection: 'column', alignItems: 'center' }}> | ||
<h2 style={{ padding: '2rem' }}> | ||
<a href='/' className='defaultcolor'>DKIM Archive</a> | ||
</h2> | ||
<SearchInput domainQuery={domainQuery} /> | ||
<DomainSearchResults initialRecords={records} domainQuery={domainQuery} /> | ||
import DomainSearchResults from "@/components/DomainSearchResults"; | ||
import { SearchInput } from "@/components/SearchInput"; | ||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
|
||
<div style={{ textAlign: 'center', marginTop: '5rem', fontSize: '0.8rem' }}> | ||
<hr style={{ width: '50%', margin: '1rem auto', borderTop: '1px solid black' }} /> | ||
<div><a href="about">About</a> this site</div> | ||
<div>Visit the project on <a href="https://github.com/zkemail/archive.prove.email">GitHub</a></div> | ||
<div>Visit <a href="https://prove.email/">Proof of Email</a></div> | ||
<div><a href="contribute">Contribute</a> to the archive</div> | ||
<div>Explore the <a href="api-explorer">API</a></div> | ||
<div>Read the <a href="privacy-policy">Privacy policy</a></div> | ||
</div> | ||
</div> | ||
) | ||
export default function Home({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) { | ||
const domainQuery = searchParams?.domain?.toString(); | ||
const [isLoading, setIsLoading] = useState(true); | ||
return ( | ||
<div style={{ display: "flex", minHeight: "100vh", flexDirection: "column", alignItems: "center" }}> | ||
<h2 style={{ padding: "2rem" }}> | ||
<Link href="/" className="defaultcolor"> | ||
DKIM Archive | ||
</Link> | ||
</h2> | ||
<SearchInput domainQuery={domainQuery} setIsLoading={setIsLoading} /> | ||
<DomainSearchResults domainQuery={domainQuery} isLoading={isLoading} setIsLoading={setIsLoading} /> | ||
<div style={{ textAlign: "center", marginTop: "5rem", fontSize: "0.8rem" }}> | ||
<hr style={{ width: "50%", margin: "1rem auto", borderTop: "1px solid black" }} /> | ||
<div> | ||
<a href="about">About</a> this site | ||
</div> | ||
<div> | ||
Visit the project on <a href="https://github.com/zkemail/archive.prove.email">GitHub</a> | ||
</div> | ||
<div> | ||
Visit <a href="https://prove.email/">Proof of Email</a> | ||
</div> | ||
<div> | ||
<a href="contribute">Contribute</a> to the archive | ||
</div> | ||
<div> | ||
Explore the <a href="api-explorer">API</a> | ||
</div> | ||
<div> | ||
Read the <a href="privacy-policy">Privacy policy</a> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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,48 @@ | ||
"use client"; | ||
import { RecordWithSelector } from "@/lib/db"; | ||
import React, { useEffect } from "react"; | ||
import { useInView } from "react-intersection-observer"; | ||
import { SelectorResult } from "./SelectorResult"; | ||
|
||
interface DomainSearchResultProps { | ||
domainQuery: string | undefined; | ||
records: RecordWithSelector[]; | ||
loadMore: () => void; | ||
cursor: number | null; | ||
} | ||
|
||
export const DomainSearchResultsDisplay: React.FC<DomainSearchResultProps> = ({ | ||
domainQuery, | ||
records, | ||
loadMore, | ||
cursor, | ||
}) => { | ||
const { ref: inViewElement, inView } = useInView(); | ||
|
||
useEffect(() => { | ||
if (inView) { | ||
loadMore(); | ||
} | ||
}, [inView]); | ||
|
||
if (!domainQuery) { | ||
return <div>Enter a search term</div>; | ||
} | ||
if (!records?.length) { | ||
return <div>No records found for "{domainQuery}"</div>; | ||
} | ||
return ( | ||
<div> | ||
<p> | ||
Search results for <b>{domainQuery}</b> | ||
</p> | ||
<div> | ||
{records.map((record) => ( | ||
<SelectorResult key={record.id} record={record} /> | ||
))} | ||
</div> | ||
{!cursor && <p>No more records</p>} | ||
<div ref={inViewElement} /> | ||
</div> | ||
); | ||
}; |
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