Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Nov 24, 2022
1 parent 8182af3 commit 69785df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 101 deletions.
101 changes: 3 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,11 @@
# Serverless Stack + Prisma - Starter Kit

## What is this?

If you want to build a serverless app with AWS CDK, Lambda, and Postgres, this is the template for you.

You can click "Use this template" button in GitHub to fork this repo. You can [merge](https://stackoverflow.com/a/69563752) in improvements in this repo to your project over time.

Clone your copy of this template, then do a search and replace for "myapp" to give it a name.

## Quickstart

### Prerequisites

Assumes you have [Node 16](https://nodejs.org/en/download/current/) installed and AWS credentials [configured](https://serverless-stack.com/chapters/configure-the-aws-cli.html).

### Setup

```shell
npm i -g pnpm # install pnpm globally
pnpm i # install dependencies + generate types from DB and GQL schemas
pnpm start # start backend
```

## Features

All features are optional, delete what you don't need.

Click links to learn more and view documentation.

- 🌩 [Serverless Stack](https://serverless-stack.com/) - powerful CDK developer experience tools
- 🌤 [AWS CDK](https://aws.amazon.com/cdk/) - cloud-native infrastructure as code
-[GraphQL API](https://docs.serverless-stack.com/constructs/GraphQLApi)
-[AWS AppSync](https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html) - serverless GraphQL AWS service
-[Code generation](https://www.graphql-code-generator.com/) of [TypeScript](https://www.graphql-code-generator.com/docs/guides/front-end-typescript-only) + [apollo client](https://www.graphql-code-generator.com/plugins/typescript-react-apollo)
- 🌐 [REST API gateway](https://docs.serverless-stack.com/api)
- 🖥 [NextJS](https://nextjs.org/) frontend w/ Material-UI
- 🎨 [Material-UI](https://mui.com/material-ui/getting-started/overview/) - react components and styling solution
- 🔓 [NextAuth.js](https://next-auth.js.org/) - authentication and session management
- 🔓 [AWS Cognito](https://aws.amazon.com/cognito/) - authentication backend
- 💾 [Prisma ORM](https://www.prisma.io/docs/)
- 📚 Prisma engine lambda layer
- 📜 Prisma DB migration CDK script
- 🐳 Database integration test setup with postgres in docker
- 🔋 [Aurora Serverless RDS](https://aws.amazon.com/rds/aurora/serverless/) PostgreSQL
- ⚡️ [Live local lambda development](https://docs.serverless-stack.com/live-lambda-development) (`pnpm start`)
- 🐞 [Lambda debugging](https://docs.sst.dev/live-lambda-development#debugging-with-visual-studio-code) - set breakpoints on your lambda functions and step through in your IDE
- 📦 [pnpm](https://pnpm.io/) - fast and correct package manager
- 🚅 [vitest](https://vitest.dev/) - fast tests
- 🐛 [ES Modules](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/)
- 🔧 [ESBuild](https://esbuild.github.io/) - fast code bundling on backend (under the hood) with tree-shaking
- 🫙 [Middy](https://middy.js.org/) - middleware for Lambda functions
- 🛠 [AWS Lambda Powertools](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/) - for [custom metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/), [structured logging](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/), and [tracing](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/).

## Package scripts

Please see [package.json](package.json) `scripts` for more.

### Start live backend dev server with AWS

```shell
pnpm start
```

### Start Nextjs frontend dev server

```shell
pnpm start:web
pnpm start:web # start nextjs dev server
```

### Start backend and frontend together
Go to /profile with the local dev server running, it is clearly intercepted by next-auth.

```shell
pnpm fullstack
```

### Run/generate DB migrations locally

```shell
pnpm db:migrate:dev
```

### Just watch and perform type-checking

```shell
pnpm watch
```

### Deploy to your AWS environment

```shell
pnpm deploy
```

### Deploy to specific AWS environment (region/profile)

```shell
pnpm deploy --region eu-west-1 --profile dev
```

### All SST/CDK commands

```shell
pnpm exec sst
pnpm exec cdk
```
Now deploy the stack with `pnpm exec sst deploy`, deploy to AWS, and see the nextjs standalone build running on lambda does not apply middleware to /profile
11 changes: 11 additions & 0 deletions web/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { withAuth } from 'next-auth/middleware';

// require authentication for certain routes
console.log('MIDDLEWARE LOAD');

export default withAuth({});

export const config = {
// apply to these routes
matcher: ['/profile/:path*'],
};
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "sst-env -- next dev --port 6020",
"dev": "next dev --port 6020",
"test": "vitest run",
"test:watch": "vitest",
"build": "next build",
Expand Down
3 changes: 1 addition & 2 deletions web/pages/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Profile } from 'web/lib/component/profile/Profile';

export default function ProfilePage() {
return <Profile />;
return "should require login"
}

0 comments on commit 69785df

Please sign in to comment.