-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into swc-up-123
- Loading branch information
Showing
103 changed files
with
142 additions
and
932 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 |
---|---|---|
|
@@ -32,3 +32,6 @@ yarn-error.log* | |
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo |
File renamed without changes.
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
10 changes: 7 additions & 3 deletions
10
...s/api-routes-rate-limit/pages/api/user.js → ...s/api-routes-rate-limit/pages/api/user.ts
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
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
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,35 @@ | ||
import type { NextApiResponse } from 'next' | ||
import LRU from 'lru-cache' | ||
|
||
type Options = { | ||
uniqueTokenPerInterval?: number | ||
interval?: number | ||
} | ||
|
||
export default function rateLimit(options?: Options) { | ||
const tokenCache = new LRU({ | ||
max: options?.uniqueTokenPerInterval || 500, | ||
ttl: options?.interval || 60000, | ||
}) | ||
|
||
return { | ||
check: (res: NextApiResponse, limit: number, token: string) => | ||
new Promise<void>((resolve, reject) => { | ||
const tokenCount = (tokenCache.get(token) as number[]) || [0] | ||
if (tokenCount[0] === 0) { | ||
tokenCache.set(token, tokenCount) | ||
} | ||
tokenCount[0] += 1 | ||
|
||
const currentUsage = tokenCount[0] | ||
const isRateLimited = currentUsage >= limit | ||
res.setHeader('X-RateLimit-Limit', limit) | ||
res.setHeader( | ||
'X-RateLimit-Remaining', | ||
isRateLimited ? 0 : limit - currentUsage | ||
) | ||
|
||
return isRateLimited ? reject() : resolve() | ||
}), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,35 +1,3 @@ | ||
# A statically generated blog example using Next.js, Markdown, and TypeScript | ||
## Deprecated | ||
|
||
This is the existing [blog-starter](https://github.com/vercel/next.js/tree/canary/examples/blog-starter) plus TypeScript. | ||
|
||
This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using Markdown files as the data source. | ||
|
||
The blog posts are stored in `/_posts` as Markdown files with front matter support. Adding a new Markdown file in there will create a new blog post. | ||
|
||
To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the Markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/blog-starter-typescript) | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/blog-starter-typescript&project-name=blog-starter-typescript&repository-name=blog-starter-typescript) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example blog-starter-typescript blog-starter-typescript-app | ||
# or | ||
yarn create next-app --example blog-starter-typescript blog-starter-typescript-app | ||
# or | ||
pnpm create next-app --example blog-starter-typescript blog-starter-typescript-app | ||
``` | ||
|
||
Your blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions). | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). | ||
|
||
# Notes | ||
|
||
`blog-starter-typescript` uses [Tailwind CSS](https://tailwindcss.com) [(v3.0)](https://tailwindcss.com/blog/tailwindcss-v3). | ||
The main [blog-starter](/examples/blog-starter) example has been refactored to use TypeScript, so this example is deprecated. |
19 changes: 0 additions & 19 deletions
19
examples/blog-starter-typescript/_posts/dynamic-routing.md
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
examples/blog-starter-typescript/components/markdown-styles.module.css
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.04 KB
examples/blog-starter-typescript/public/assets/blog/authors/jj.jpeg
Binary file not shown.
Binary file removed
BIN
-7.03 KB
examples/blog-starter-typescript/public/assets/blog/authors/joe.jpeg
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-115 KB
examples/blog-starter-typescript/public/assets/blog/dynamic-routing/cover.jpg
Binary file not shown.
Binary file removed
BIN
-103 KB
examples/blog-starter-typescript/public/assets/blog/hello-world/cover.jpg
Binary file not shown.
Binary file removed
BIN
-43.2 KB
examples/blog-starter-typescript/public/assets/blog/preview/cover.jpg
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.