From 094536449dc146e5ee70ff3ddd3c2cbe4cb89d2e Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 11 Feb 2021 14:28:44 +0300 Subject: [PATCH] remove node server from project --- Dockerfile | 2 +- package.json | 24 ++---------- src/client/common/urls.js | 11 ------ .../services/CalculationService/index.ts | 4 +- src/client/services/CrmService/client.ts | 3 +- src/client/services/CrmService/index.ts | 7 +++- .../Effects/actions/createKP.js | 1 - src/core/constants/urls.js | 11 ------ src/index.tsx | 6 --- src/server/index.ts | 19 --------- src/server/routes/index.ts | 8 ---- src/server/routes/proxy.ts | 15 ------- src/server/tsconfig.json | 15 ------- webpack.config.server.js | 39 ------------------- 14 files changed, 11 insertions(+), 154 deletions(-) delete mode 100644 src/client/common/urls.js delete mode 100644 src/server/index.ts delete mode 100644 src/server/routes/index.ts delete mode 100644 src/server/routes/proxy.ts delete mode 100644 src/server/tsconfig.json delete mode 100644 webpack.config.server.js diff --git a/Dockerfile b/Dockerfile index acfb491..9f72b8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN npm install --only=prod COPY . /app -RUN npm run build:client +RUN npm run build FROM nginx:alpine diff --git a/package.json b/package.json index 3e5c5ad..4412601 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "@testing-library/user-event": "^7.1.2", "antd": "^4.9.4", "axios": "^0.21.1", - "cors": "^2.8.5", "craco-less": "^1.17.1", "graphql": "^15.4.0", "js-cookie": "^2.2.1", @@ -36,38 +35,21 @@ "validator": "^13.5.1" }, "devDependencies": { - "@types/cors": "^2.8.8", - "@types/express": "^4.17.9", "@types/jest": "^26.0.15", "@types/lodash": "^4.14.165", "@types/luxon": "^1.25.0", - "@types/node": "^14.14.12", "@types/pluralize": "^0.0.29", "@types/react-router-dom": "^5.1.6", "@types/styled-components": "^5.1.2", "@types/styled-system": "^5.1.10", "cross-env": "^7.0.3", - "express": "^4.17.1", - "express-http-proxy": "^1.6.2", - "http-proxy-middleware": "^1.0.6", - "nodemon": "^2.0.6", - "rimraf": "^3.0.2", - "wait-on": "^5.2.0", - "webpack-cli": "^4.2.0", - "webpack-node-externals": "^2.5.2" + "dotenv": "^8.2.0" }, "scripts": { "test": "craco test", "eject": "react-scripts eject", - "dev": "cross-env NODE_ENV=development REACT_APP_CRM=dev concurrently -p name -c \"yellow,magenta,blue\" -n \"webpack-server,nodemon-server,CRA\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\" \"npm run dev:client\"", - "dev:client:only": "craco start", - "dev:client": "wait-on -l tcp:3001 && craco start", - "dev:server": "concurrently -p name -c \"yellow,magenta\" -n \"webpack-server,nodemon-server\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\"", - "dev:server:webpack": "webpack --config webpack.config.server.js --watch", - "dev:server:nodemon": "rimraf build/server.js && wait-on -l build/server.js && nodemon build/server.js", - "build": "npm run build:client && npm run build:server", - "build:client": "craco build", - "build:server": "webpack --config webpack.config.server.js" + "start": "cross-env NODE_ENV=development REACT_APP_CRM=dev craco start", + "build": "craco build" }, "eslintConfig": { "extends": "react-app" diff --git a/src/client/common/urls.js b/src/client/common/urls.js deleted file mode 100644 index 1ed11b4..0000000 --- a/src/client/common/urls.js +++ /dev/null @@ -1,11 +0,0 @@ -import { SERVER_PORT } from 'core/constants/urls'; - -export const API_HOSTNAME = window.location.hostname; - -export const getServerUrl = (...url) => - String.prototype.concat( - (process.env.NODE_ENV === 'development' && - `http://${API_HOSTNAME}:${SERVER_PORT}`) || - '', - ...url, - ); diff --git a/src/client/services/CalculationService/index.ts b/src/client/services/CalculationService/index.ts index e5cf897..10e3464 100644 --- a/src/client/services/CalculationService/index.ts +++ b/src/client/services/CalculationService/index.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import { getServerUrl } from 'client/common/urls'; import { CORE_PROXY_URL } from 'core/constants/urls'; import { IPreparedData } from 'core/types/Calculation/Requests'; import { IGetCalculationResponse } from 'core/types/Calculation/Responses'; @@ -11,8 +10,7 @@ export default class { new Promise((resolve, reject) => { axios .post( - getServerUrl( - '/proxy', + String.prototype.concat( CORE_PROXY_URL, '/api', '/v1', diff --git a/src/client/services/CrmService/client.ts b/src/client/services/CrmService/client.ts index 49f1499..ffc3670 100644 --- a/src/client/services/CrmService/client.ts +++ b/src/client/services/CrmService/client.ts @@ -1,8 +1,7 @@ import { ApolloClient, InMemoryCache } from '@apollo/client'; -import { getServerUrl } from 'client/common/urls'; import { CRM_PROXY_URL } from 'core/constants/urls'; export default new ApolloClient({ - uri: getServerUrl('/proxy', CRM_PROXY_URL, '/'), + uri: String.prototype.concat('/proxy', CRM_PROXY_URL, '/'), cache: new InMemoryCache(), }); diff --git a/src/client/services/CrmService/index.ts b/src/client/services/CrmService/index.ts index c85941e..263c9ab 100644 --- a/src/client/services/CrmService/index.ts +++ b/src/client/services/CrmService/index.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import { getServerUrl } from 'client/common/urls'; import { CRM_PROXY_URL } from 'core/constants/urls'; import { ICreateKpRequest, @@ -103,7 +102,11 @@ export default class { new Promise((resolve, reject) => { axios .post( - getServerUrl('/proxy', CRM_PROXY_URL, '/offer', '/leasingcalculator'), + String.prototype.concat( + CRM_PROXY_URL, + '/offer', + '/leasingcalculator', + ), data, ) .then(res => { diff --git a/src/client/stores/CalculationStore/Effects/actions/createKP.js b/src/client/stores/CalculationStore/Effects/actions/createKP.js index fa07046..407f074 100644 --- a/src/client/stores/CalculationStore/Effects/actions/createKP.js +++ b/src/client/stores/CalculationStore/Effects/actions/createKP.js @@ -85,7 +85,6 @@ export default async () => { calculationUrls.setUrl({ name: 'kpUrl', url: String.prototype.concat( - '/proxy', CRM_PROXY_URL, new_quote.offerprintformapi, ), diff --git a/src/core/constants/urls.js b/src/core/constants/urls.js index 2917c75..8d15417 100644 --- a/src/core/constants/urls.js +++ b/src/core/constants/urls.js @@ -1,13 +1,2 @@ -export const SERVER_PORT = 3001; - -export const CRM_URL = - process.env.REACT_APP_CRM === 'dev' - ? 'http://crmgraphql-dev.evoleasing.ru' - : 'http://crm-graphql.evoleasing.ru'; export const CRM_PROXY_URL = '/crmgraphql'; - -export const CORE_URL = - process.env.NODE_ENV === 'development' - ? 'http://localhost:5000' - : 'http://core:5000'; export const CORE_PROXY_URL = '/core'; diff --git a/src/index.tsx b/src/index.tsx index 07eacb3..8b27c95 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,14 +1,8 @@ -import axios from 'axios'; import React from 'react'; import ReactDOM from 'react-dom'; import App from './client/App'; import * as serviceWorker from './client/serviceWorker'; import './index.css'; -import { getServerUrl } from 'client/common/urls'; - -if (process.env.NODE_ENV === 'development') { - axios.defaults.baseURL = getServerUrl(); -} ReactDOM.render( // diff --git a/src/server/index.ts b/src/server/index.ts deleted file mode 100644 index 5dd4e35..0000000 --- a/src/server/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import cors from 'cors'; -import express from 'express'; -import { SERVER_PORT } from './../core/constants/urls'; -import routes from './routes'; - -const app = express(); - -/**EXTENTIONS */ -app.use(cors({ origin: process.env.NODE_ENV === 'development' && '*' })); -/**EXTENTIONS */ - -/**ROUTES */ -app.use('/', routes); -/**ROUTES */ - -app.listen(SERVER_PORT, () => { - console.log('ENV: ', process.env.NODE_ENV); - console.log(`Server now listening on port: ${SERVER_PORT}`); -}); diff --git a/src/server/routes/index.ts b/src/server/routes/index.ts deleted file mode 100644 index 7b39006..0000000 --- a/src/server/routes/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import proxy from './proxy'; - -const routes = Router(); - -routes.use('/proxy', proxy); - -export default routes; diff --git a/src/server/routes/proxy.ts b/src/server/routes/proxy.ts deleted file mode 100644 index 061db90..0000000 --- a/src/server/routes/proxy.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Router } from 'express'; -import proxy from 'express-http-proxy'; -import { - CRM_PROXY_URL, - CRM_URL, - CORE_URL, - CORE_PROXY_URL, -} from '../../core/constants/urls'; - -const router = Router(); - -router.use(CRM_PROXY_URL, proxy(CRM_URL)); -router.use(CORE_PROXY_URL, proxy(CORE_URL)); - -export default router; diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json deleted file mode 100644 index 8b7285a..0000000 --- a/src/server/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "../../dist", - "noEmit": false, - "sourceMap": true, - "module": "esnext", - "strict": true, - "target": "esnext", - "moduleResolution": "node", - "noImplicitAny": false - }, - "exclude": ["../../build", "../client"], - "include": ["."] -} diff --git a/webpack.config.server.js b/webpack.config.server.js deleted file mode 100644 index 61840c2..0000000 --- a/webpack.config.server.js +++ /dev/null @@ -1,39 +0,0 @@ -const path = require('path'); -const nodeExternals = require('webpack-node-externals'); - -module.exports = { - mode: process.env.NODE_ENV || 'development', - target: 'node', - devtool: 'inline-source-map', - entry: { server: './src/server/index.ts' }, - output: { - path: path.resolve(__dirname, 'build'), - filename: '[name].js', - }, - resolve: { - extensions: ['.ts', '.tsx', '.js'], - }, - // don't compile node_modules - externals: [nodeExternals()], - optimization: { - splitChunks: { - chunks: 'all', - }, - }, - module: { - rules: [ - { - test: /\.tsx?$/, - use: [ - { - loader: 'ts-loader', - options: { - // use the tsconfig in the server directory - configFile: 'src/server/tsconfig.json', - }, - }, - ], - }, - ], - }, -};