Skip to content

Commit

Permalink
[#1] Fix proxy middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Aug 30, 2023
1 parent 6562b4d commit 3b6c046
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 68 deletions.
95 changes: 95 additions & 0 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
90 changes: 90 additions & 0 deletions frontend/eslint.all.json
Original file line number Diff line number Diff line change
@@ -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
}
}
85 changes: 55 additions & 30 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
10 changes: 10 additions & 0 deletions frontend/release.sh
Original file line number Diff line number Diff line change
@@ -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
44 changes: 7 additions & 37 deletions frontend/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -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,
})
);
};
2 changes: 1 addition & 1 deletion frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 3b6c046

Please sign in to comment.