Skip to content

Commit

Permalink
feat: change all config values to vite env
Browse files Browse the repository at this point in the history
  • Loading branch information
jinho-choi123 committed Nov 3, 2023
1 parent e1d3cd7 commit a827b15
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
API_SERVER_URL=
VITE_API_SERVER_URL=
VITE_ANIMATION_DURATION=
VITE_TRANSITION_INTERVAL=
VITE_ZABO_SHARE_URL=
2 changes: 1 addition & 1 deletion src/components/Background/Background.animation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnimationDuration } from "@/config";
const AnimationDuration = import.meta.env.VITE_ANIMATION_DURATION;

export const backgroundFadeIn = {
to: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Board/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { Info } from "@/components/Info";
import { Background } from "@/components/Background";
import { Qr } from "@/components/Qr";
import { Logo } from "@/components/Logo";
import { TransitionInterval } from "@/config";
import style from "./Board.module.scss";

const TransitionInterval = import.meta.env.VITE_TRANSITION_INTERVAL;

export const Board = () => {
const zaboList = useAppSelector((state: ZaboListState) => state.zaboList);
const leftOverZaboLength = useAppSelector(
Expand Down
2 changes: 1 addition & 1 deletion src/components/Info/Info.animation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnimationDuration } from "@/config";
const AnimationDuration = import.meta.env.VITE_ANIMATION_DURATION;

export const infoFadeIn = {
to: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Qr/Qr.animation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnimationDuration } from "@/config";
const AnimationDuration = import.meta.env.VITE_ANIMATION_DURATION;

export const qrFadeIn = {
to: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Zabo/Zabo.animation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AnimationDuration } from "@/config";
const AnimationDuration = import.meta.env.VITE_ANIMATION_DURATION;

export const zaboMoveToBefore = {
to: {
x: 3145,
opacity: 1,
opacity: 0.5,
},
config: {
duration: AnimationDuration,
Expand Down
11 changes: 4 additions & 7 deletions src/redux/zabos/fetchZaboThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import axios from "axios";
import dayjs from "dayjs";
import type { AppDispatch } from "@/redux/store";
import { ZaboState, type ZaboJson } from "@/types";
import { ZABO_SHARE_BASE_URL } from "@/config";
import { pushZabos } from "./zaboSlice";

const ZABO_SHARE_URL = import.meta.env.VITE_ZABO_SHARE_URL;

export const fetchZaboThunk = () => async (dispatch: AppDispatch) => {
// attach timestamp to image url to prevent browser cache
// this leads to animation crash
Expand All @@ -19,7 +20,7 @@ export const fetchZaboThunk = () => async (dispatch: AppDispatch) => {
// important thing is that, we have to set lastSeen params to get zabos after lastSeen
// so we can not do 5 requests in parallel. it should be sequential
let zabosData: ZaboJson[] = [];
for (let i = 0; i < 1; i += 1) {
for (let i = 0; i < 5; i += 1) {
const lastFetched =
zabosData.length > 0 ? zabosData[zabosData.length - 1].id : null;

Expand Down Expand Up @@ -50,11 +51,7 @@ export const fetchZaboThunk = () => async (dispatch: AppDispatch) => {
zabo.schedules.length > 0
? dayjs(zabo.schedules[0].startAt).format("MM.DD")
: null;
const qrUrl = "".concat(
ZABO_SHARE_BASE_URL,
"/s/",
id.substring(id.length - 6),
);
const qrUrl = "".concat(ZABO_SHARE_URL, id.substring(id.length - 6));
const imageUrl =
zabo.photos.length > 0 ? zabo.photos[0].url + postFix(index) : null;
const state = ZaboState.PENDING_STATE;
Expand Down
21 changes: 11 additions & 10 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import tsconfigPaths from "vite-tsconfig-paths";
import dotenv from "dotenv";

dotenv.config();

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), tsconfigPaths()],
server: {
proxy: {
"/api": process.env.API_SERVER_URL,
export default defineConfig(({ mode }) => {
const TmpEnv = loadEnv(mode, process.cwd());

return {
plugins: [react(), tsconfigPaths()],
server: {
proxy: {
"/api": TmpEnv.VITE_API_SERVER_URL,
},
},
},
};
});

0 comments on commit a827b15

Please sign in to comment.