remove node server from project

This commit is contained in:
Chika 2021-02-11 14:28:44 +03:00
parent 0c1eb7329d
commit 094536449d
14 changed files with 11 additions and 154 deletions

View File

@ -12,7 +12,7 @@ RUN npm install --only=prod
COPY . /app
RUN npm run build:client
RUN npm run build
FROM nginx:alpine

View File

@ -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"

View File

@ -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,
);

View File

@ -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<IGetCalculationResponse>(
getServerUrl(
'/proxy',
String.prototype.concat(
CORE_PROXY_URL,
'/api',
'/v1',

View File

@ -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(),
});

View File

@ -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<IQuote>(
getServerUrl('/proxy', CRM_PROXY_URL, '/offer', '/leasingcalculator'),
String.prototype.concat(
CRM_PROXY_URL,
'/offer',
'/leasingcalculator',
),
data,
)
.then(res => {

View File

@ -85,7 +85,6 @@ export default async () => {
calculationUrls.setUrl({
name: 'kpUrl',
url: String.prototype.concat(
'/proxy',
CRM_PROXY_URL,
new_quote.offerprintformapi,
),

View File

@ -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';

View File

@ -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(
// <React.StrictMode>

View File

@ -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}`);
});

View File

@ -1,8 +0,0 @@
import { Router } from 'express';
import proxy from './proxy';
const routes = Router();
routes.use('/proxy', proxy);
export default routes;

View File

@ -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;

View File

@ -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": ["."]
}

View File

@ -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',
},
},
],
},
],
},
};