[REF]: refactor env strategy

This commit is contained in:
behnamrhp 2023-07-06 12:38:36 +03:00
parent 872a49329c
commit d75c9c489d
14 changed files with 86 additions and 114 deletions

View File

@ -9,3 +9,4 @@ tailwind.config.cjs
postcss.config.cjs
fileMock.js
jest.config.js
/src/types

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ chrome-user-data
.vscode
*.swp
*.swo
dist/

View File

@ -1,7 +1,7 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6C5.46957 2 4.96086 2.21071 4.58579 2.58579C4.21071 2.96086 4 3.46957 4 4V20C4 20.5304 4.21071 21.0391 4.58579 21.4142C4.96086 21.7893 5.46957 22 6 22H18C18.5304 22 19.0391 21.7893 19.4142 21.4142C19.7893 21.0391 20 20.5304 20 20V8L14 2Z" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 2V8H20" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 13H8" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 17H8" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10 9H9H8" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
<svg fill="#fff" width="197px" height="197px" viewBox="-2.08 -2.08 20.16 20.16" id="add-user-16px" xmlns="http://www.w3.org/2000/svg" stroke="#fff">
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
<g id="SVGRepo_iconCarrier"> <path id="Path_179" data-name="Path 179" d="M29.991,8a4,4,0,1,0-4-4A4,4,0,0,0,29.991,8Zm0-7a3,3,0,1,1-3,3A3,3,0,0,1,29.991,1ZM31,15.5a.5.5,0,0,1-.5.5h-7A1.5,1.5,0,0,1,22,14.5,4.505,4.505,0,0,1,26.5,10h4a.5.5,0,0,1,0,1h-4A3.5,3.5,0,0,0,23,14.5a.5.5,0,0,0,.5.5h7A.5.5,0,0,1,31,15.5Zm7-3a.5.5,0,0,1-.5.5H35v2.5a.5.5,0,0,1-1,0V13H31.5a.5.5,0,0,1,0-1H34V9.5a.5.5,0,0,1,1,0V12h2.5A.5.5,0,0,1,38,12.5Z" transform="translate(-22)"/> </g>
</svg>

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 928 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

10
dist/index.html vendored
View File

@ -2,11 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="module" crossorigin src="/assets/index-43ad9ab6.js"></script>
<link rel="stylesheet" href="/assets/index-32cf486f.css">
<script src="/env/env.js"></script>
<title>Dipal admin panel</title>
<script type="module" crossorigin src="/assets/index-5e9e94de.js"></script>
<link rel="stylesheet" href="/assets/index-e0bca659.css">
</head>
<body>
<div id="root"></div>

1
dist/vite.svg vendored
View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -3,7 +3,18 @@ services:
dipal-admin:
ports:
- 8000:80
env_file: .env.production
environment:
- VITE_API_ORIGIN=http://behnam/api/v1
- VITE_API_AUTH_ORIGIN=http://176.53.196.42:5000/api/v1/auth
- VITE_API_AUTH_PHONENUMBER=/start-challenge
- VITE_API_AUTH_LOGIN=/login
- VITE_API_AUTH_REFRESH=/refresh-token
- VITE_API_CREATE_MEMBER=/user_place/members
- VITE_API_PLACES=/place
- VITE_API_USERS=/profile
- VITE_API_USERS_ACCOUNT=/account
- VITE_API_USERS_PROFILE=/profile
- VITE_API_QR=/qr_code
build:
context: .
dockerfile: dockerfile.prod

View File

@ -14,8 +14,7 @@ COPY --from=build /usr/app/dist /usr/share/nginx/html
RUN touch /var/run/nginx.pid
RUN chown -R nginx:nginx /var/run/nginx.pid /var/cache/nginx /var/log/nginx /etc/nginx/conf.d
USER nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
CMD ["/bin/sh", "-c", "envsubst < /usr/share/nginx/html/env/env.template.js > /usr/share/nginx/html/env/env.js && exec nginx -g 'daemon off;'"]

View File

@ -4,6 +4,8 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="/env/env.js"></script>
<title>Dipal admin panel</title>
</head>
<body>

13
public/env/env.js vendored Normal file
View File

@ -0,0 +1,13 @@
const ENV = Object.freeze({
VITE_API_ORIGIN: 'http://176.53.196.42:6001/api/v1',
VITE_API_AUTH_ORIGIN: 'http://176.53.196.42:5000/api/v1/auth',
VITE_API_AUTH_PHONENUMBER: '/start-challenge',
VITE_API_AUTH_LOGIN: '/login',
VITE_API_AUTH_REFRESH: '/refresh-token',
VITE_API_CREATE_MEMBER: '/user_place/members',
VITE_API_PLACES: '/place',
VITE_API_USERS: '/profile',
VITE_API_USERS_ACCOUNT: '/account',
VITE_API_USERS_PROFILE: '/profile',
VITE_API_QR: '/qr_code',
});

13
public/env/env.template.js vendored Normal file
View File

@ -0,0 +1,13 @@
const ENV = Object.freeze({
VITE_API_ORIGIN: '${VITE_API_ORIGIN}',
VITE_API_AUTH_ORIGIN: '${VITE_API_AUTH_ORIGIN}',
VITE_API_AUTH_PHONENUMBER: '${VITE_API_AUTH_PHONENUMBER}',
VITE_API_AUTH_LOGIN: '${VITE_API_AUTH_LOGIN}',
VITE_API_AUTH_REFRESH: '${VITE_API_AUTH_REFRESH}',
VITE_API_CREATE_MEMBER: '${VITE_API_CREATE_MEMBER}',
VITE_API_PLACES: '${VITE_API_PLACES}',
VITE_API_USERS: '${VITE_API_USERS}',
VITE_API_USERS_ACCOUNT: '${VITE_API_USERS_ACCOUNT}',
VITE_API_USERS_PROFILE: '${VITE_API_USERS_PROFILE}',
VITE_API_QR: '${VITE_API_QR}',
});

View File

@ -1,14 +1,14 @@
export const ENVs = {
apiOrigin: process.env.VITE_API_ORIGIN,
apiAuthOrigin: process.env.VITE_API_AUTH_ORIGIN,
apiAuthPhonenumber: process.env.VITE_API_AUTH_PHONENUMBER,
apiAuthLogin: process.env.VITE_API_AUTH_LOGIN,
apiAuthRefresh: process.env.VITE_API_AUTH_REFRESH,
apiGetPlaces: process.env.VITE_API_PLACES,
apiGetUsers: process.env.VITE_API_USERS,
apiCreateUserAccount: process.env.VITE_API_USERS_ACCOUNT,
apiQr: process.env.VITE_API_QR,
apiCreateUserProfile: process.env.VITE_API_USERS_PROFILE,
apiCreateMember: process.env.VITE_API_CREATE_MEMBER,
apiCreatePlace: process.env.VITE_API_PLACES,
apiOrigin: ENV.VITE_API_ORIGIN,
apiAuthOrigin: ENV.VITE_API_AUTH_ORIGIN,
apiAuthPhonenumber: ENV.VITE_API_AUTH_PHONENUMBER,
apiAuthLogin: ENV.VITE_API_AUTH_LOGIN,
apiAuthRefresh: ENV.VITE_API_AUTH_REFRESH,
apiGetPlaces: ENV.VITE_API_PLACES,
apiGetUsers: ENV.VITE_API_USERS,
apiCreateUserAccount: ENV.VITE_API_USERS_ACCOUNT,
apiQr: ENV.VITE_API_QR,
apiCreateUserProfile: ENV.VITE_API_USERS_PROFILE,
apiCreateMember: ENV.VITE_API_CREATE_MEMBER,
apiCreatePlace: ENV.VITE_API_PLACES,
};

17
src/types/global.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
declare global {
var ENV: {
VITE_API_ORIGIN: string;
VITE_API_AUTH_ORIGIN: string;
VITE_API_AUTH_PHONENUMBER: string;
VITE_API_AUTH_LOGIN: string;
VITE_API_AUTH_REFRESH: string;
VITE_API_CREATE_MEMBER: string;
VITE_API_PLACES: string;
VITE_API_USERS: string;
VITE_API_USERS_ACCOUNT: string;
VITE_API_USERS_PROFILE: string;
VITE_API_QR: string;
};
}
export {};