Skip to content

Commit 321bc21

Browse files
committed
Add Next.js feature test app
1 parent 5116872 commit 321bc21

31 files changed

+2442
-0
lines changed

example/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
21+
# debug
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# local env files
27+
.env.local
28+
.env.development.local
29+
.env.test.local
30+
.env.production.local

example/components/date.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { parseISO, format } from "date-fns";
2+
3+
export default function Date({ dateString }) {
4+
const date = parseISO(dateString);
5+
return <time dateTime={dateString}>{format(date, "LLLL d, yyyy")}</time>;
6+
}

example/components/layout.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Head from "next/head";
2+
import styles from "./layout.module.css";
3+
import Link from "next/link";
4+
5+
const name = "Frank";
6+
export const siteTitle = "Next.js Sample Website";
7+
8+
export default function Layout({ children, home }) {
9+
return (
10+
<div className={styles.container}>
11+
<Head>
12+
<link rel="icon" href="/favicon.ico" />
13+
<meta
14+
name="description"
15+
content="Learn how to build a personal website using Next.js"
16+
/>
17+
<meta
18+
property="og:image"
19+
content={`https://og-image.vercel.app/${encodeURI(
20+
siteTitle
21+
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`}
22+
/>
23+
<meta name="og:title" content={siteTitle} />
24+
<meta name="twitter:card" content="summary_large_image" />
25+
</Head>
26+
<main>{children}</main>
27+
{!home && (
28+
<div className={styles.backToHome}>
29+
<Link href="/">
30+
← Back to home
31+
</Link>
32+
</div>
33+
)}
34+
</div>
35+
);
36+
}

example/components/layout.module.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.container {
2+
max-width: 36rem;
3+
padding: 0 1rem;
4+
margin: 3rem auto 6rem;
5+
}
6+
7+
.header {
8+
display: flex;
9+
flex-direction: column;
10+
align-items: center;
11+
}
12+
13+
.backToHome {
14+
margin: 3rem 0 0;
15+
}

example/middleware.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { NextResponse } from "next/server";
2+
3+
export async function middleware(request) {
4+
if (request.nextUrl.pathname === "/middleware-redirect") {
5+
return NextResponse.redirect(new URL("/middleware-redirect-destination", request.url));
6+
}
7+
if (request.nextUrl.pathname === "/middleware-set-header") {
8+
// Clone the request headers and set a new header `x-hello-from-middleware1`
9+
const requestHeaders = new Headers(request.headers);
10+
requestHeaders.set("x-hello-from-middleware1", "hello");
11+
12+
// You can also set request headers in NextResponse.rewrite
13+
const response = NextResponse.next({
14+
request: {
15+
// New request headers
16+
headers: requestHeaders,
17+
},
18+
});
19+
20+
// Set a new response header `x-hello-from-middleware2`
21+
response.headers.set("x-hello-from-middleware2", "hello");
22+
return response;
23+
}
24+
if (request.nextUrl.pathname === "/middleware-fetch") {
25+
console.log(await fetch("https://webhook.site/facbcacc-08f2-4fb1-b67f-a26e3382b64e"));
26+
return NextResponse.next();
27+
}
28+
}
29+
30+
export const config = {
31+
matcher: ["/middleware-redirect", "/middleware-set-header", "/middleware-fetch"],
32+
}

example/next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
swcMinify: true,
5+
output: "standalone"
6+
}
7+
8+
module.exports = nextConfig

0 commit comments

Comments
 (0)