diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index bec3256..f2ca59f 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -31,7 +31,7 @@ jobs: run: | IMAGE_ID=ghcr.io/dataesr/ticket-office IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - docker build -t $IMAGE_ID:staging . --file Dockerfile --build-arg VITE_SCANR_API_AUTHORIZATION=${{ secrets.VITE_SCANR_API_AUTHORIZATION }} + docker build -t $IMAGE_ID:staging . --build-arg VITE_SCANR_API_AUTHORIZATION=${{ secrets.VITE_SCANR_API_AUTHORIZATION }} - name: 📦 Push Docker image run: | diff --git a/Dockerfile b/Dockerfile index dd4ede6..9fe4e1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,6 @@ -FROM node:18-alpine - -WORKDIR /app - -COPY package*.json . - -RUN npm install - -COPY . . - -ARG VITE_SCANR_API_AUTHORIZATION - -ENV VITE_SCANR_API_AUTHORIZATION=VITE_SCANR_API_AUTHORIZATION - -RUN npm run build - +FROM nginx:stable +COPY dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/templates/nginx.conf.template +ENV API_KEY VITE_SCANR_API_AUTHORIZATION EXPOSE 5173 -CMD [ "npm", "run", "preview" ] - diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9a288d1 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 5173; + resolver 8.8.8.8; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } + location ~ ^/api/(.*)$ { + proxy_set_header Authorization 'Basic $API_KEY'; + proxy_set_header Accept application/json; + proxy_set_header Content-Type application/json; + client_max_body_size 10M; + } +} diff --git a/package-lock.json b/package-lock.json index ac57438..5d2d3a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "sib-api-v3-sdk": "^8.5.0" }, "devDependencies": { + "@types/node": "^20.12.7", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.15", "@typescript-eslint/eslint-plugin": "^6.10.0", @@ -2856,6 +2857,15 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/prop-types": { "version": "15.7.12", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", @@ -6030,6 +6040,12 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -6163,12 +6179,6 @@ } } }, - "node_modules/vite-plugin-env": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/vite-plugin-env/-/vite-plugin-env-1.0.1.tgz", - "integrity": "sha512-yP4Xc/tACFI+odh3vUF2nnU350VbcCk0qrM05petxYEd9Zyn6kKUW4wmTTQRHY+hPWk7ar4og7xj6OfcU20WIA==", - "dev": true - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -6209,4 +6219,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 7655551..c82a760 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "sib-api-v3-sdk": "^8.5.0" }, "devDependencies": { + "@types/node": "^20.12.7", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.15", "@typescript-eslint/eslint-plugin": "^6.10.0", @@ -35,4 +36,4 @@ "typescript": "^5.2.2", "vite": "^5.0.4" } -} \ No newline at end of file +} diff --git a/src/api/contribution-api/useGetObjectContributeData.tsx b/src/api/contribution-api/useGetObjectContributeData.tsx index 75a61d2..92c6e5a 100644 --- a/src/api/contribution-api/useGetObjectContributeData.tsx +++ b/src/api/contribution-api/useGetObjectContributeData.tsx @@ -1,20 +1,16 @@ import { useState, useEffect } from "react"; +import { postHeaders } from "../../config/api"; -function useGetContributionData(URL: {}, reload: unknown) { +function useGetContributionData(URL: unknown, reload: unknown) { const [data, setData] = useState({}); const [isLoading, setLoading] = useState(true); const [isError, setError] = useState(false); - - const { VITE_SCANR_API_AUTHORIZATION } = import.meta.env; useEffect(() => { async function getData() { - const url = URL; + const url = URL as RequestInfo; try { - const response = await fetch(url as RequestInfo, { - headers: { - Authorization: VITE_SCANR_API_AUTHORIZATION, - "Content-Type": "application/json", - }, + const response = await fetch(url, { + headers: postHeaders, }); const res = await response.json(); setData(res); diff --git a/src/api/utils/buildURL.tsx b/src/api/utils/buildURL.tsx index ff94ab7..452d66d 100644 --- a/src/api/utils/buildURL.tsx +++ b/src/api/utils/buildURL.tsx @@ -13,7 +13,6 @@ export const buildURL = ( : "contact"; const sorted = sort === "ASC" ? "sort=created_at" : "sort=-created_at"; const where: any = {}; - console.log("test"); if (query.trim() !== "") { where.$or = [{ name: { $regex: `.*${query}.*`, $options: "i" } }]; if (searchInMessages) { diff --git a/src/config/api.ts b/src/config/api.ts index e69de29..81f0307 100644 --- a/src/config/api.ts +++ b/src/config/api.ts @@ -0,0 +1,3 @@ +const { VITE_SCANR_API_AUTHORIZATION: API_KEY } = import.meta.env; +export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {}; +export const postHeaders = { ...headers, "Content-Type": "application/json" }; diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/tsconfig.json b/tsconfig.json index 93c41ce..89c4e67 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,10 @@ { "compilerOptions": { - "target": "ESNext", - "lib": ["DOM", "DOM.Iterable", "ESNext"], + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, - "types": ["vite/client"], /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, @@ -12,11 +12,8 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - "declaration": true, - "esModuleInterop": true, - "declarationMap": true, /* Linting */ - "strict": true, + "strict": false, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true