-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(next-example): add edge example and publish to vercel
- Loading branch information
Showing
9 changed files
with
118 additions
and
45 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,36 +1,9 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
# Example for next and vercel edge functions | ||
|
||
## Getting Started | ||
Make sure it's work in vercel enviroment. | ||
|
||
First, run the development server: | ||
Links: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. | ||
https://xior-next-example.vercel.app/ | ||
https://xior-next-example.vercel.app/api/hello-edge | ||
https://xior-next-example.vercel.app/api/hello-node |
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,9 @@ | ||
import { http } from '@/app/http'; | ||
|
||
export const runtime = 'edge'; | ||
export const dynamic = 'force-dynamic'; // static by default, unless reading the request | ||
|
||
export async function GET(request: Request) { | ||
const { data } = await http.get('https://google.com'); | ||
return new Response(`Hello from ${process.env.VERCEL_REGION} ${data.length}`); | ||
} |
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,9 @@ | ||
import { http } from '@/app/http'; | ||
|
||
export const runtime = 'nodejs'; | ||
export const dynamic = 'force-dynamic'; // static by default, unless reading the request | ||
|
||
export async function GET(request: Request) { | ||
const { data } = await http.get('https://google.com'); | ||
return new Response(`Hello from ${process.env.VERCEL_REGION} ${data.length}`); | ||
} |
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 @@ | ||
import xior from 'xior'; | ||
import cachePlugin from 'xior/plugins/cache'; | ||
import errorRetryPlugin from 'xior/plugins/error-retry'; | ||
import uploadDownloadProgressPlugin from 'xior/plugins/progress'; | ||
import throttlePlugin from 'xior/plugins/throttle'; | ||
|
||
export const http = xior.create(); | ||
|
||
http.plugins.use(errorRetryPlugin()); | ||
http.plugins.use(throttlePlugin()); | ||
http.plugins.use(cachePlugin()); | ||
http.plugins.use(uploadDownloadProgressPlugin()); |
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,28 @@ | ||
import xior from 'xior'; | ||
import cachePlugin from 'xior/plugins/cache'; | ||
import errorRetryPlugin from 'xior/plugins/error-retry'; | ||
import uploadDownloadProgressPlugin from 'xior/plugins/progress'; | ||
import throttlePlugin from 'xior/plugins/throttle'; | ||
|
||
export const http = xior.create(); | ||
|
||
http.plugins.use(errorRetryPlugin()); | ||
http.plugins.use(throttlePlugin()); | ||
http.plugins.use(cachePlugin()); | ||
http.plugins.use(uploadDownloadProgressPlugin()); | ||
|
||
import { NextResponse } from 'next/server'; | ||
|
||
export async function middleware(request) { | ||
const { data } = await http.get('https://google.com'); // for test | ||
console.log(data.length); | ||
} | ||
|
||
export const config = { | ||
matcher: [ | ||
// Skip all internal paths (_next) | ||
'/((?!_next).*)', | ||
// Optional: only run on root (/) URL | ||
// '/' | ||
], | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.