From 3b6c04611a17a8148b836bea6a3de1762dfa9c91 Mon Sep 17 00:00:00 2001 From: dedenbangkit Date: Wed, 30 Aug 2023 13:31:58 +0700 Subject: [PATCH] [#1] Fix proxy middleware --- frontend/.eslintrc.json | 95 ++++++++++++++++++++++++++++++++++++++ frontend/eslint.all.json | 90 ++++++++++++++++++++++++++++++++++++ frontend/package.json | 85 ++++++++++++++++++++++------------ frontend/release.sh | 10 ++++ frontend/src/setupProxy.js | 44 +++--------------- frontend/yarn.lock | 2 +- 6 files changed, 258 insertions(+), 68 deletions(-) create mode 100644 frontend/.eslintrc.json create mode 100644 frontend/eslint.all.json create mode 100755 frontend/release.sh diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json new file mode 100644 index 0000000..2cae0e2 --- /dev/null +++ b/frontend/.eslintrc.json @@ -0,0 +1,95 @@ +{ + "parser": "@babel/eslint-parser", + "settings": { + "react": { + "version": "detect" + } + }, + "plugins": [ + "react", + "react-hooks", + "import", + "export", + "jest", + "jsx-a11y" + ], + "parserOptions": { + "requireConfigFile": false, + "sourceType": "module", + "babelOptions": { + "presets": [ + "@babel/preset-react" + ] + } + }, + "rules": { + "no-alert": "warn", + "no-console": [ + "warn", + { + "allow": [ + "error", + "info" + ] + } + ], + "no-undef": "warn", + "no-else-return": "warn", + "no-unused-vars": "warn", + "no-undefined": "warn", + "no-unreachable": "warn", + "no-extra-semi": "warn", + "no-duplicate-case": "warn", + "no-useless-escape": "warn", + "no-multi-spaces": [ + "warn", + { + "ignoreEOLComments": true + } + ], + "eqeqeq": "warn", + "semi": "warn", + "no-delete-var": "warn", + "prefer-const": "warn", + "prefer-arrow-callback": "error", + "react/prefer-stateless-function": "warn", + "react-hooks/rules-of-hooks": "warn", + "react-hooks/exhaustive-deps": "warn", + "react/prop-types": "off", + "react/react-in-jsx-scope": "off", + "react/jsx-filename-extension": [ + "error", + { + "extensions": [ + ".js", + ".jsx" + ] + } + ], + "curly": "error" + }, + "env": { + "browser": true, + "node": true, + "es6": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:prettier/recommended" + ], + "overrides": [ + { + "files": [ + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.test.jsx", + "**/*.test.js" + ], + "env": { + "jest": true + } + } + ] +} diff --git a/frontend/eslint.all.json b/frontend/eslint.all.json new file mode 100644 index 0000000..432022c --- /dev/null +++ b/frontend/eslint.all.json @@ -0,0 +1,90 @@ +{ + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "script", + "ecmaFeatures": { + "jsx": true + } + }, + "rules": { + "constructor-super": 2, + "for-direction": 2, + "getter-return": 2, + "no-async-promise-executor": 2, + "no-case-declarations": 2, + "no-class-assign": 2, + "no-compare-neg-zero": 2, + "no-cond-assign": 2, + "no-const-assign": 2, + "no-constant-condition": 2, + "no-control-regex": 2, + "no-debugger": 2, + "no-delete-var": 2, + "no-dupe-args": 2, + "no-dupe-class-members": 2, + "no-dupe-else-if": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty": 2, + "no-empty-character-class": 2, + "no-empty-pattern": 2, + "no-ex-assign": 2, + "no-extra-boolean-cast": 2, + "no-extra-semi": 2, + "no-fallthrough": 2, + "no-func-assign": 2, + "no-global-assign": 2, + "no-import-assign": 2, + "no-inner-declarations": 2, + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-loss-of-precision": 2, + "no-misleading-character-class": 2, + "no-mixed-spaces-and-tabs": 2, + "no-new-symbol": 2, + "no-nonoctal-decimal-escape": 2, + "no-obj-calls": 2, + "no-octal": 2, + "no-prototype-builtins": 2, + "no-redeclare": 2, + "no-regex-spaces": 2, + "no-self-assign": 2, + "no-setter-return": 2, + "no-shadow-restricted-names": 2, + "no-sparse-arrays": 2, + "no-this-before-super": 2, + "no-undef": 2, + "no-unexpected-multiline": 2, + "no-unreachable": 2, + "no-unsafe-finally": 2, + "no-unsafe-negation": 2, + "no-unsafe-optional-chaining": 2, + "no-unused-labels": 2, + "no-unused-vars": 2, + "no-useless-backreference": 2, + "no-useless-catch": 2, + "no-useless-escape": 2, + "no-with": 2, + "require-yield": 2, + "use-isnan": 2, + "valid-typeof": 2, + "no-console": 2, + "max-depth": 2, + "jsx-quotes": 2, + "key-spacing": 2, + "func-style": 2, + "func-names": 2, + "default-case": 2, + "brace-style": 2, + "capitalized-comments": 2, + "complexity": 2, + "no-useless-rename": 2, + "no-useless-return": 2, + "no-undefined": 2, + "max-statements": 2, + "no-alert": 2 + }, + "env": { + "es6": false + } +} \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index a26eab8..c4bc63e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,32 +1,57 @@ { - "name": "myapp", - "version": "0.1.0", - "private": true, - "dependencies": { - "@testing-library/jest-dom": "^5.17.0", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-scripts": "5.0.1", - "web-vitals": "^2.1.4", - "http-proxy-middleware": "^2.0.2" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": ["react-app", "react-app/jest"] - }, - "browserslist": { - "production": [">0.2%", "not dead", "not op_mini all"], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } + "name": "myapp", + "version": "0.1.0", + "private": true, + "dependencies": { + "akvo-react-form": "^2.2.3", + "axios": "^0.25.0", + "axios-mock-adapter": "^1.21.1", + "pullstate": "^1.23.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-scripts": "5.0.1", + "web-vitals": "^2.1.4" + }, + "devDependencies": { + "@babel/core": "^7.16.12", + "@babel/eslint-parser": "^7.16.5", + "@babel/preset-react": "^7.16.7", + "@testing-library/dom": "^8.11.3", + "@testing-library/jest-dom": "^5.16.1", + "@testing-library/react": "^12.1.2", + "@testing-library/user-event": "^13.5.0", + "axios-mock-adapter": "^1.21.1", + "cross-env": "^7.0.3", + "eslint": "^8.7.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-export": "^0.1.2", + "eslint-plugin-jsx-a11y": "^6.5.1", + "eslint-plugin-prettier": "^4.0.0", + "http-proxy-middleware": "^2.0.2", + "jest-canvas-mock": "^2.4.0", + "node-sass": "^7.0.1", + "prettier": "^2.5.1", + "react-test-renderer": "^17.0.2", + "yarn-audit-fix": "^9.3.1" + }, + "scripts": { + "start": "react-scripts start", + "lint": "eslint --config .eslintrc.json src --ext .js,.jsx", + "prettier": "prettier --check src", + "build": "react-scripts build", + "test": "react-scripts test --updateSnapshot --transformIgnorePatterns \"node_modules/(?!d3|d3-geo|d3-array|internmap|delaunator|robust-predicates)/\"", + "test:ci": "CI=true react-scripts test --watchAll=false --coverage --transformIgnorePatterns \"node_modules/(?!d3|d3-geo|d3-array|internmap|delaunator|robust-predicates)/\"", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": ["react-app", "react-app/jest"] + }, + "browserslist": { + "production": [">0.2%", "not dead", "not op_mini all"], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } } diff --git a/frontend/release.sh b/frontend/release.sh new file mode 100755 index 0000000..039c2e2 --- /dev/null +++ b/frontend/release.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +#shellcheck disable=SC2039 + +set -euo pipefail + +yarn install --no-progress --frozen-lock +yarn eslint --config .eslintrc.prod.json src --ext .js,.jsx +yarn prettier --check src/ +yarn test:ci +yarn build diff --git a/frontend/src/setupProxy.js b/frontend/src/setupProxy.js index 6f1b3eb..9403a9c 100644 --- a/frontend/src/setupProxy.js +++ b/frontend/src/setupProxy.js @@ -1,41 +1,11 @@ const { createProxyMiddleware } = require("http-proxy-middleware"); module.exports = function (app) { - app.use( - ["/api/**", "/static/**"], - createProxyMiddleware({ - target: "http://localhost:8000", - changeOrigin: true, - }) - ); - app.use( - ["/config.js"], - createProxyMiddleware({ - target: "http://localhost:8000", - changeOrigin: true, - pathRewrite: { - "^/config.js": "/api/v1/config.js", - }, - }) - ); - app.use( - ["/app"], - createProxyMiddleware({ - target: "http://localhost:8000", - changeOrigin: true, - pathRewrite: { - "^/app": "/api/v1/device/apk/download", - }, - }) - ); - app.use( - ["/i18n.js"], - createProxyMiddleware({ - target: "http://localhost:8000", - changeOrigin: true, - pathRewrite: { - "^/i18n.js": "/api/v1/i18n.js", - }, - }) - ); + app.use( + ["/api/**", "/static-files/**"], + createProxyMiddleware({ + target: "http://localhost:8000", + changeOrigin: true, + }) + ); }; diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 5b0bb1a..ed1d2a8 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -5049,7 +5049,7 @@ http-proxy-agent@^4.0.1: agent-base "6" debug "4" -http-proxy-middleware@^2.0.3: +http-proxy-middleware@^2.0.2, http-proxy-middleware@^2.0.3: version "2.0.6" resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz#e1a4dd6979572c7ab5a4e4b55095d1f32a74963f" integrity sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw==