Skip to content

Commit 8ecb655

Browse files
committed
feat: reducing to a simple express server with a Todo API
1 parent fd26b99 commit 8ecb655

28 files changed

+1169
-5766
lines changed

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.env
3+
.env.*
4+
.gitignore
5+
docker-compose.yml
6+
Dockerfile
7+
README.md

.eslintrc.json

-3
This file was deleted.

Dockerfile

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
FROM node:20-alpine AS base
2-
ENV NEXT_TELEMETRY_DISABLED 1
32
WORKDIR /app
43

54
FROM base AS deps
65
COPY package-lock.json ./package-lock.json
76
COPY package.json ./package.json
87
RUN npm install
98

10-
FROM base as dev
11-
COPY --from=deps /app/node_modules ./node_modules
12-
COPY . .
9+
FROM base AS prod-deps
10+
COPY package-lock.json ./package-lock.json
11+
COPY package.json ./package.json
12+
RUN npm install --omit=dev
1313

14-
FROM base AS builder
14+
FROM base AS dev
1515
COPY --from=deps /app/node_modules ./node_modules
16-
RUN npm run build
16+
COPY . .
1717

1818
FROM base AS runner
1919
ENV NODE_ENV production
20-
RUN addgroup --system --gid 1001 nodejs \
21-
&& adduser --system --uid 1001 nextjs
22-
23-
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
24-
25-
# Set the correct permission for prerender cache
26-
RUN mkdir .next \
27-
&& chown nextjs:nodejs .next
28-
29-
# Automatically leverage output traces to reduce image size
30-
# https://nextjs.org/docs/advanced-features/output-file-tracing
31-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone .
32-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
33-
34-
USER nextjs
20+
COPY --from=prod-deps /app/node_modules ./node_modules
21+
COPY . .
3522

3623
ENV PORT 3000
3724

@@ -42,4 +29,4 @@ ENV HOSTNAME "0.0.0.0"
4229

4330
# server.js is created by next build from the standalone output
4431
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
45-
CMD ["node", "./server.js"]
32+
CMD ["node", "."]

README.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
11
This is a [Redis](https://redis.io/) starter template for JS and [Node](https://nodejs.org/) using:
22

33
- [Redis Cloud](https://redis.io/try-free/)
4-
- [Next.js](https://nextjs.org)
5-
- [Tailwind CSS](https://tailwindcss.com/)
4+
- [Express](https://expressjs.com/)
65

76
## Getting started
87

98
Copy and edit the `.env` file:
109

1110
```bash
1211
cp .env.example .env.docker
13-
cp .env.example .env.local
12+
cp .env.example .env
1413
```
1514

16-
Your `.env.local` file should contain the connection string you copied from Redis Cloud.
15+
Your `.env` file should contain the connection string you copied from Redis Cloud.
1716

18-
Your `.env.docker` file will look similar to `.env.local`, but should use the appropriate docker internal URLs. Here is
17+
Your `.env.docker` file will look similar to `.env`, but should use the appropriate docker internal URLs. Here is
1918
an example:
2019

2120
```bash
2221
API_URL="http://app:3000"
23-
NEXT_PUBLIC_API_URL="http://localhost:3000"
2422
REDIS_URL="redis://redis:6379"
2523
```
2624

27-
Next, install dependencies:
28-
29-
```bash
30-
npm i
31-
```
32-
33-
Then, spin up docker containers:
25+
Next, spin up docker containers:
3426

3527
```bash
3628
docker compose up -d
3729
```
3830

39-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
31+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. You can now edit the files in
32+
`./server` and it will update the docker container and restart the server.
4033

4134

4235
## Running locally outside docker

docker-compose.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ services:
88
replicas: 1
99
restart_policy:
1010
condition: on-failure
11-
app:
12-
container_name: app
11+
server:
12+
container_name: server
1313
build:
1414
context: ./
1515
dockerfile: ./Dockerfile
@@ -21,10 +21,8 @@ services:
2121
- ./.env
2222
- ./.env.docker
2323
volumes:
24-
- ./.next:/app/.next
25-
- ./src:/app/src
24+
- ./server:/app/server
2625
- /app/node_modules
27-
- /app/.next
2826
restart: always
2927
depends_on:
3028
- redis

next.config.ts

-7
This file was deleted.

0 commit comments

Comments
 (0)