Skip to content

Commit 2bc516c

Browse files
authored
Adding Next.js example (sst#837)
1 parent 83ff124 commit 2bc516c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+45434
-598
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ package-lock.json
1313
/examples/**/build/**/*.*
1414
/www/.docusaurus/**/*.*
1515
/www/build/*.*
16+
# Ignore Next.js outputs
17+
/examples/**/.next/**/*.*

examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ A collection of example serverless apps built with SST.
3838
| [websocket](https://github.com/serverless-stack/serverless-stack/tree/master/examples/websocket) | Create a serverless WebSocket API on AWS using the [`WebSocketApi`](https://docs.serverless-stack.com/constructs/WebSocketApi) construct to define the routes of our API. | [Link](https://serverless-stack.com/examples/how-to-create-a-websocket-api-with-serverless.html) |
3939
| [react-app](https://github.com/serverless-stack/serverless-stack/tree/master/examples/react-app) | Create a full-stack serverless React.js click counter app on AWS using the [`ReactStaticSite`](https://docs.serverless-stack.com/constructs/ReactStaticSite) construct. | [Link](https://serverless-stack.com/examples/how-to-create-a-reactjs-app-with-serverless.html) |
4040
| [react-app-auth-cognito](https://github.com/serverless-stack/serverless-stack/tree/master/examples/react-app-auth-cognito) | Create a full-stack serverless React.js app that connects to an API secured using Cognito. Uses the [`ReactStaticSite`](https://docs.serverless-stack.com/constructs/ReactStaticSite) and [`Auth`](https://docs.serverless-stack.com/constructs/Auth) construct. | [Link](https://serverless-stack.com/chapters/using-cognito-to-add-authentication-to-a-serverless-app.html) |
41+
| [nextjs-app](https://github.com/serverless-stack/serverless-stack/tree/master/examples/nextjs-app) | Create a full-stack serverless Next.js click counter app on AWS using the [`NextjsSite`](https://docs.serverless-stack.com/constructs/NextjsSite) construct. | [Link](https://serverless-stack.com/examples/how-to-create-a-nextjs-app-with-serverless.html) |
4142
| [cron-job](https://github.com/serverless-stack/serverless-stack/tree/master/examples/cron-job) | Create a cron job in your serverless app using the [`Cron`](https://docs.serverless-stack.com/constructs/Cron) construct. | [Link](https://serverless-stack.com/examples/how-to-use-cron-jobs-in-your-serverless-app.html) |
4243
| [queue](https://github.com/serverless-stack/serverless-stack/tree/master/examples/queue) | Create a queue system in your serverless app using the [`Api`](https://docs.serverless-stack.com/constructs/Api) and [`Queue`](https://docs.serverless-stack.com/constructs/Queue) constructs. | [Link](https://serverless-stack.com/examples/how-to-use-queues-in-your-serverless-app.html) |
4344
| [pub-sub](https://github.com/serverless-stack/serverless-stack/tree/master/examples/pub-sub) | Create a pub/sub system in your serverless app using the [`Api`](https://docs.serverless-stack.com/constructs/Api) and [`Topic`](https://docs.serverless-stack.com/constructs/Topic) constructs. | [Link](https://serverless-stack.com/examples/how-to-use-pub-sub-in-your-serverless-app.html) |

examples/api-auth-jwt-cognito-user-pool/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ An example serverless app created with SST.
66

77
[**Read the tutorial**](https://serverless-stack.com/examples/how-to-add-jwt-authorization-with-cognito-user-pool-to-a-serverless-api.html)
88

9-
109
Install the example.
1110

1211
```bash

examples/api-auth-lambda-authorizer-iam-response/src/authorizer.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ export const main = async (event) => {
1818
Statement: [
1919
{
2020
Action: "execute-api:Invoke",
21-
Effect: username === "admin" && password === "password" ? "Allow" : "Deny",
22-
Resource: "*"
23-
}
24-
]
21+
Effect:
22+
username === "admin" && password === "password" ? "Allow" : "Deny",
23+
Resource: "*",
24+
},
25+
],
2526
},
2627
context: {
2728
username,
28-
}
29+
},
2930
};
3031
};

examples/api-auth-lambda-authorizer-simple-response/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ This example creates an Api endpoint with a `/private` route and a `/public` rou
66

77
## Getting Started
88

9-
109
Install the example.
1110

1211
```bash

examples/api-auth-lambda-authorizer-simple-response/src/authorizer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export const main = async (event) => {
1515
isAuthorized: username === "admin" && password === "password",
1616
context: {
1717
username,
18-
}
18+
},
1919
};
2020
};

examples/nextjs-app/.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These variables are only available in your SST code.
2+
# To apply them to your Lambda functions, checkout this doc - https://docs.serverless-stack.com/environment-variables#environment-variables-in-lambda-functions
3+
4+
MY_ENV_VAR=i-am-an-environment-variable

examples/nextjs-app/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
12+
# misc
13+
.DS_Store
14+
15+
# sst build output
16+
.build
17+
.sst
18+
19+
# environments
20+
.env*.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*

examples/nextjs-app/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# How to create a Next.js app
2+
3+
An example full-stack serverless Next.js app created with SST.
4+
5+
## Getting Started
6+
7+
[**Read the tutorial**](https://serverless-stack.com/examples/how-to-create-a-nextjs-app-with-serverless.html)
8+
9+
Install the example.
10+
11+
```bash
12+
$ npm init serverless-stack --example nextjs-app
13+
# Or with Yarn
14+
$ yarn create serverless-stack --example nextjs-app
15+
```
16+
17+
## Commands
18+
19+
### `npm run start`
20+
21+
Starts the Live Lambda Development environment.
22+
23+
### `npm run build`
24+
25+
Build your app and synthesize your stacks.
26+
27+
### `npm run deploy [stack]`
28+
29+
Deploy all your stacks to AWS. Or optionally deploy, a specific stack.
30+
31+
### `npm run remove [stack]`
32+
33+
Remove all your stacks and all of their resources from AWS. Or optionally removes, a specific stack.
34+
35+
### `npm run test`
36+
37+
Runs your tests using Jest. Takes all the [Jest CLI options](https://jestjs.io/docs/en/cli).
38+
39+
## Documentation
40+
41+
Learn more about the SST.
42+
43+
- [Docs](https://docs.serverless-stack.com/)
44+
- [@serverless-stack/cli](https://docs.serverless-stack.com/packages/cli)
45+
- [@serverless-stack/resources](https://docs.serverless-stack.com/packages/resources)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
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).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
12+
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16+
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
18+
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
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.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
reactStrictMode: true,
3+
};

0 commit comments

Comments
 (0)