|
1 | 1 | # Create T3 App
|
2 | 2 |
|
3 | 3 | This is an app bootstrapped according to the [init.tips](https://init.tips) stack, also known as the T3-Stack.
|
| 4 | + |
| 5 | +## Why are there `.js` files in here? |
| 6 | + |
| 7 | +As per [T3-Axiom #3](https://github.com/t3-oss/create-t3-app/tree/next#3-typesafety-isnt-optional), we believe take typesafety as a first class citizen. Unfortunately, not all frameworks and plugins support TypeScript which means some of the configuration files have to be `.js` files. |
| 8 | + |
| 9 | +We try to emphasize that these files are javascript for a reason, by explicitly declaring its type (`cjs` or `mjs`) depending on what's supported by the library it is used by. Also, all the `js` files in this project are still typechecked using a `@ts-check` comment at the top. |
| 10 | + |
| 11 | +## What's next? How do I make an app with this? |
| 12 | + |
| 13 | +We try to keep this project as simple as possible, so you can start with the most basic configuration and then move on to more advanced configuration. |
| 14 | + |
| 15 | +If you are not familiar with the different technologies used in this project, please refer to the respective docs. If you still are in the wind, please join our [Discord](https://t3.gg/discord) and ask for help. |
| 16 | + |
| 17 | +- [Next-Auth.js](https://next-auth.js.org) |
| 18 | +- [Prisma](https://prisma.io) |
| 19 | +- [TailwindCSS](https://tailwindcss.com) |
| 20 | +- [tRPC](https://trpc.io) (using @next version? [see v10 docs here](https://alpha.trpc.io)) |
| 21 | + |
| 22 | +## How do I deploy this? |
| 23 | + |
| 24 | +### Vercel |
| 25 | + |
| 26 | +We recommend deploying to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_campaign=oss). It makes it super easy to deploy NextJs apps. |
| 27 | + |
| 28 | +- Push your code to a GitHub repository. |
| 29 | +- Go to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_campaign=oss) and sign up with GitHub. |
| 30 | +- Create a Project and import the repository you pushed your code to. |
| 31 | +- Add your environment variables. |
| 32 | +- Click **Deploy** |
| 33 | +- Now whenever you push a change to your repository, Vercel will automatically redeploy your website! |
| 34 | + |
| 35 | +### Docker |
| 36 | + |
| 37 | +You can also dockerize this stack and deploy a container. |
| 38 | + |
| 39 | +1. In your [next.config.mjs](./next.config.mjs), add the `output: "standalone"` option to your config. |
| 40 | +2. Create a `.dockerignore` file with the following contents: |
| 41 | + <details> |
| 42 | + <summary>.dockerignore</summary> |
| 43 | + |
| 44 | + ``` |
| 45 | + Dockerfile |
| 46 | + .dockerignore |
| 47 | + node_modules |
| 48 | + npm-debug.log |
| 49 | + README.md |
| 50 | + .next |
| 51 | + .git |
| 52 | + ``` |
| 53 | + |
| 54 | + </details> |
| 55 | + |
| 56 | +3. Create a `Dockerfile` with the following contents: |
| 57 | + <details> |
| 58 | + <summary>Dockerfile</summary> |
| 59 | + |
| 60 | + ```Dockerfile |
| 61 | + # Install dependencies only when needed |
| 62 | + FROM node:16-alpine AS deps |
| 63 | + # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
| 64 | + RUN apk add --no-cache libc6-compat |
| 65 | + WORKDIR /app |
| 66 | + |
| 67 | + # Install dependencies based on the preferred package manager |
| 68 | + COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ |
| 69 | + RUN \ |
| 70 | + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ |
| 71 | + elif [ -f package-lock.json ]; then npm ci; \ |
| 72 | + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ |
| 73 | + else echo "Lockfile not found." && exit 1; \ |
| 74 | + fi |
| 75 | + |
| 76 | + |
| 77 | + # Rebuild the source code only when needed |
| 78 | + FROM node:16-alpine AS builder |
| 79 | + WORKDIR /app |
| 80 | + COPY --from=deps /app/node_modules ./node_modules |
| 81 | + COPY . . |
| 82 | + |
| 83 | + # Next.js collects completely anonymous telemetry data about general usage. |
| 84 | + # Learn more here: https://nextjs.org/telemetry |
| 85 | + # Uncomment the following line in case you want to disable telemetry during the build. |
| 86 | + # ENV NEXT_TELEMETRY_DISABLED 1 |
| 87 | + |
| 88 | + RUN yarn build |
| 89 | + |
| 90 | + # If using npm comment out above and use below instead |
| 91 | + # RUN npm run build |
| 92 | + |
| 93 | + # Production image, copy all the files and run next |
| 94 | + FROM node:16-alpine AS runner |
| 95 | + WORKDIR /app |
| 96 | + |
| 97 | + ENV NODE_ENV production |
| 98 | + # Uncomment the following line in case you want to disable telemetry during runtime. |
| 99 | + # ENV NEXT_TELEMETRY_DISABLED 1 |
| 100 | + |
| 101 | + RUN addgroup --system --gid 1001 nodejs |
| 102 | + RUN adduser --system --uid 1001 nextjs |
| 103 | + |
| 104 | + # You only need to copy next.config.js if you are NOT using the default configuration |
| 105 | + # COPY --from=builder /app/next.config.js ./ |
| 106 | + COPY --from=builder /app/public ./public |
| 107 | + COPY --from=builder /app/package.json ./package.json |
| 108 | + |
| 109 | + # Automatically leverage output traces to reduce image size |
| 110 | + # https://nextjs.org/docs/advanced-features/output-file-tracing |
| 111 | + COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ |
| 112 | + COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static |
| 113 | + |
| 114 | + USER nextjs |
| 115 | + |
| 116 | + EXPOSE 3000 |
| 117 | + |
| 118 | + ENV PORT 3000 |
| 119 | + |
| 120 | + CMD ["node", "server.js"] |
| 121 | + ``` |
| 122 | + |
| 123 | + </details> |
| 124 | + |
| 125 | +4. You can now build an image to deploy yourself, or use a PaaS such as [Railway's](https://railway.app) automated [Dockerfile deployments](https://docs.railway.app/deploy/dockerfiles) to deploy your app. |
| 126 | + |
| 127 | +## Useful resources |
| 128 | + |
| 129 | +Here are some resources that we commonly refer to: |
| 130 | + |
| 131 | +- [Protecting routes with Next-Auth.js](https://next-auth.js.org/configuration/nextjs#unstable_getserversession) |
0 commit comments