Skip to content

Commit

Permalink
Feat: add client container
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Jan 22, 2024
1 parent 3dc6f05 commit 1b62cf6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Empty file added .github/workflows/client.yaml
Empty file.
23 changes: 23 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:20 AS builder
ARG oauth_server
ARG client_id
ARG api_base
ARG redirect_url

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

COPY . .
ENV VITE_OAUTH_SERVER=$oauth_server
ENV VITE_CLIENT_ID=$client_id
ENV VITE_API_BASE=$api_base
ENV VITE_REDIRECT_URL=$redirect_url
RUN npm run build

FROM nginx:stable-alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
9 changes: 9 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}
5 changes: 3 additions & 2 deletions client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { jwtDecode } from 'jwt-decode'
const OAUTH_SERVER = import.meta.env.VITE_OAUTH_SERVER
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID
const API_BASE = import.meta.env.VITE_API_BASE
const REDIRECT_URL = import.meta.env.VITE_REDIRECT_URL
const SCOPES = ['openid', 'user/basic', 'media']

const urlParams = new URLSearchParams(window.location.search)
Expand All @@ -17,7 +18,7 @@ if (urlParams.has('code') && urlParams.get('state') === localStorage.getItem('st
body: new URLSearchParams({
grant_type: 'authorization_code',
code: code || '',
redirect_uri: 'http://localhost:5173',
redirect_uri: REDIRECT_URL,
client_id: CLIENT_ID
}).toString(),
})
Expand All @@ -32,7 +33,7 @@ const decoded = token ? jwtDecode<{ exp: number }>(token) : null
if (!token || (decoded?.exp||0) * 1000 < Date.now()) {
const state = crypto.randomUUID()
localStorage.setItem('state', state)
window.location.href = `${OAUTH_SERVER}/authorize?response_type=code&client_id=${CLIENT_ID}&redirect_uri=http://localhost:5173&scope=${SCOPES.join(' ')}&state=${state}`
window.location.href = `${OAUTH_SERVER}/authorize?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&scope=${SCOPES.join(' ')}&state=${state}`
}

export default new Api({
Expand Down
3 changes: 3 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ export default defineConfig({
alias: {
$lib: '/src/lib'
}
},
build: {
target: 'esnext'
}
})

0 comments on commit 1b62cf6

Please sign in to comment.