From 69785df8a5f1b7737a8770f27d5dd24ed707e116 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Thu, 24 Nov 2022 05:02:42 +0000 Subject: [PATCH] docs --- README.md | 101 ++---------------------------------------- web/middleware.ts | 11 +++++ web/package.json | 2 +- web/pages/profile.tsx | 3 +- 4 files changed, 16 insertions(+), 101 deletions(-) create mode 100644 web/middleware.ts diff --git a/README.md b/README.md index c5029d5..b418ecd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/web/middleware.ts b/web/middleware.ts new file mode 100644 index 0000000..9d24a96 --- /dev/null +++ b/web/middleware.ts @@ -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*'], +}; diff --git a/web/package.json b/web/package.json index 7c89837..5b9a5ee 100644 --- a/web/package.json +++ b/web/package.json @@ -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", diff --git a/web/pages/profile.tsx b/web/pages/profile.tsx index 9fb4cac..6529d2a 100644 --- a/web/pages/profile.tsx +++ b/web/pages/profile.tsx @@ -1,5 +1,4 @@ -import { Profile } from 'web/lib/component/profile/Profile'; export default function ProfilePage() { - return ; + return "should require login" }