Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60f1970

Browse files
committed
feat: web app build
1 parent 88464c0 commit 60f1970

File tree

11 files changed

+99
-23
lines changed

11 files changed

+99
-23
lines changed

‎.docker/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# docker
22
COMPOSE_PROJECT_NAME=spring-boot-example
33
TIMEZONE=America/Sao_Paulo
4+
5+
# api
46
API_PORT=8080
57
API_DEBUG_PORT=8000
8+
9+
# web
610
APP_PORT=3000
11+
APP_API_BASE_URL=http://localhost:8080/api
712

813
# database
914
DB_HOST=database

‎.docker/docker-compose.dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ services:
103103
networks:
104104
- spring-boot-example-network
105105
tty: true
106+
environment:
107+
APP_PORT: ${APP_PORT}
108+
VITE_API_BASE_URL: ${APP_API_BASE_URL}
106109
entrypoint: [
107110
"dockerize",
108111
"-wait",

‎.docker/docker-compose.prod.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,20 @@ services:
7373
"api.jar"
7474
]
7575

76-
# web:
77-
# image: throyer/springboot/example-web:latest
78-
# build:
79-
# context: ../web
80-
# dockerfile: ../web/docker/Dockerfile.prod
81-
# restart: unless-stopped
82-
# container_name: ${COMPOSE_PROJECT_NAME}-web
83-
# ports:
84-
# - "8082:80"
85-
# networks:
86-
# - spring-boot-example-network
87-
# tty: true
76+
web:
77+
image: throyer/springboot/example-web:latest
78+
build:
79+
context: ../web
80+
dockerfile: ../web/docker/Dockerfile.prod
81+
args:
82+
- APP_API_BASE_URL=${APP_API_BASE_URL}
83+
restart: unless-stopped
84+
container_name: ${COMPOSE_PROJECT_NAME}-web
85+
ports:
86+
- "8082:80"
87+
networks:
88+
- spring-boot-example-network
89+
tty: true
8890

8991
networks:
9092
spring-boot-example-network:

‎web/docker/Dockerfile.prod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:16.14.2 as BUILDER
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
7+
ARG APP_API_BASE_URL
8+
9+
ENV VITE_API_BASE_URL $APP_API_BASE_URL
10+
11+
RUN npm set cache ./.npm
12+
RUN --mount=type=cache,target=/usr/src/app/.npm npm install
13+
14+
RUN npm run build
15+
16+
FROM nginx:1.23.1-alpine
17+
18+
COPY --from=BUILDER /app/dist /var/www/web-app
19+
COPY ./docker/nginx.conf /etc/nginx/nginx.conf

‎web/docker/nginx.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
worker_processes 1;
2+
3+
events {
4+
worker_connections 1024;
5+
}
6+
7+
http {
8+
include mime.types;
9+
sendfile on;
10+
11+
server {
12+
listen 80;
13+
listen [::]:80;
14+
15+
resolver 127.0.0.11;
16+
autoindex off;
17+
18+
server_name _;
19+
server_tokens off;
20+
21+
root /var/www/web-app;
22+
gzip_static on;
23+
}
24+
}

‎web/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"devDependencies": {
2525
"@types/luxon": "^3.0.1",
26+
"@types/node": "^16.0.0",
2627
"@types/react": "^18.0.17",
2728
"@types/react-dom": "^18.0.6",
2829
"@vitejs/plugin-react": "^2.1.0",

‎web/src/http/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from "axios";
33
import { useSession } from '../providers/session';
44

55
const ENV = {
6-
BASE_URL: "http://localhost:8080/api"
6+
BASE_URL: import.meta.env.VITE_API_BASE_URL
77
}
88

99
export const api = axios.create({

‎web/src/pages/login/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { useAuthentication } from "../../hooks/use-authentication/use-authentica
1212
import { useUser } from "../../providers/user";
1313

1414
export const Login = () => {
15-
1615
const { login } = useAuthentication();
1716
const { user } = useUser();
1817

‎web/src/vite-env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_API_BASE_URL: string;
5+
}
6+
7+
interface ImportMeta {
8+
readonly env: ImportMetaEnv;
9+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /