server is only for dev & fix getUser

This commit is contained in:
Chika 2020-12-22 21:14:03 +03:00
parent f1191811ae
commit 4e0e0de5fb
20 changed files with 46 additions and 147 deletions

2
.env
View File

@ -1,2 +0,0 @@
GENERATE_SOURCEMAP=false
REACT_APP_CRM=dev

2
.gitignore vendored
View File

@ -13,6 +13,7 @@
# misc # misc
.DS_Store .DS_Store
.env
.env.local .env.local
.env.development.local .env.development.local
.env.test.local .env.test.local
@ -25,3 +26,4 @@ yarn.lock
*.log *.log
package-lock.json package-lock.json
/.vscode /.vscode
.eslintcache

View File

@ -1,5 +1,9 @@
FROM node:14-alpine as builder FROM node:14-alpine as builder
ENV NODE_ENV=production
ENV REACT_APP_CRM=prod
ENV GENERATE_SOURCEMAP=false
WORKDIR /app WORKDIR /app
COPY package.json /app/ COPY package.json /app/

View File

@ -2,8 +2,6 @@ version: '3.3'
services: services:
auth: auth:
build: ./EvoCalculator.Auth build: ./EvoCalculator.Auth
ports:
- '8888:8888'
networks: networks:
- calc_network - calc_network
restart: always restart: always
@ -25,6 +23,8 @@ services:
proxy: proxy:
restart: always restart: always
build: ./EvoCalculator.Proxy build: ./EvoCalculator.Proxy
environment:
- CRM_URL=http://...
ports: ports:
- '4000:80' - '4000:80'
networks: networks:

View File

@ -1,5 +1,5 @@
{ {
"name": "evo_calculator", "name": "evocalculator.client",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@apollo/client": "^3.3.4", "@apollo/client": "^3.3.4",
@ -9,29 +9,16 @@
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2", "@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2", "@testing-library/user-event": "^7.1.2",
"@types/graphql": "^14.5.0", "antd": "^4.9.4",
"antd": "^4.9.2", "axios": "^0.21.1",
"axios": "^0.21.0",
"body-parser": "^1.19.0",
"class-validator": "^0.12.2",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5", "cors": "^2.8.5",
"craco-less": "^1.17.1", "craco-less": "^1.17.1",
"cross-fetch": "^3.0.6",
"dotenv": "^8.2.0",
"dotenv-webpack": "^6.0.0",
"express": "^4.17.1",
"express-http-proxy": "^1.6.2",
"express-ntlm": "^2.5.2",
"graphql": "^15.4.0", "graphql": "^15.4.0",
"helmet": "^4.2.0",
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"luxon": "^1.25.0", "luxon": "^1.25.0",
"mobx": "^6.0.4", "mobx": "^6.0.4",
"mobx-react-lite": "^3.1.6", "mobx-react-lite": "^3.1.6",
"morgan": "^1.10.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"pluralize": "^8.0.0", "pluralize": "^8.0.0",
"react": "^17.0.1", "react": "^17.0.1",
@ -39,50 +26,47 @@
"react-router": "^5.2.0", "react-router": "^5.2.0",
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"react-scripts": "^4.0.1", "react-scripts": "^4.0.1",
"recompose": "^0.30.0",
"reflect-metadata": "^0.1.13",
"styled-components": "^5.2.1", "styled-components": "^5.2.1",
"styled-system": "^5.1.5", "styled-system": "^5.1.5",
"ts-loader": "^8.0.11", "ts-loader": "^8.0.12",
"typescript": "4.1.2", "typescript": "4.1.3",
"use-debounce": "^5.1.0", "use-debounce": "^5.1.0",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"validator": "^13.5.1" "validator": "^13.5.1"
}, },
"devDependencies": { "devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/compression": "^1.7.0",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.8", "@types/cors": "^2.8.8",
"@types/express": "^4.17.9", "@types/express": "^4.17.9",
"@types/express-http-proxy": "^1.6.1",
"@types/jest": "^26.0.15", "@types/jest": "^26.0.15",
"@types/lodash": "^4.14.165", "@types/lodash": "^4.14.165",
"@types/luxon": "^1.25.0", "@types/luxon": "^1.25.0",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.12", "@types/node": "^14.14.12",
"@types/pluralize": "^0.0.29", "@types/pluralize": "^0.0.29",
"@types/react-router-dom": "^5.1.6", "@types/react-router-dom": "^5.1.6",
"@types/styled-components": "^5.1.2", "@types/styled-components": "^5.1.2",
"@types/styled-system": "^5.1.10", "@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", "http-proxy-middleware": "^1.0.6",
"nodemon": "^2.0.6", "nodemon": "^2.0.6",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"wait-on": "^5.2.0",
"webpack-cli": "^4.2.0", "webpack-cli": "^4.2.0",
"webpack-node-externals": "^2.5.2" "webpack-node-externals": "^2.5.2"
}, },
"scripts": { "scripts": {
"test": "craco test", "test": "craco test",
"eject": "react-scripts eject", "eject": "react-scripts eject",
"dev": "cross-env NODE_ENV=development dotenv -e .env -- 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": "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:only": "craco start",
"dev:client": "wait-on -l tcp:3001 && 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": "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: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", "dev:server:nodemon": "rimraf build/server.js && wait-on -l build/server.js && nodemon build/server.js",
"build": "dotenv -e .env npm run build:client && npm run build:server", "build": "npm run build:client && npm run build:server",
"build:client": "craco build", "build:client": "craco build",
"build:server": "cross-env NODE_ENV=production webpack --config webpack.config.server.js" "build:server": "webpack --config webpack.config.server.js"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "react-app" "extends": "react-app"

View File

@ -9,21 +9,21 @@ import systemUserQuery from './queries/systemUserQuery';
export default () => export default () =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const { username: UserName, domainname: DomainName, FullName } = getUser(); const { domainname } = getUser();
Promise.all([ Promise.all([
CrmService.crmgqlquery({ CrmService.crmgqlquery({
...initialOwnerQuery, ...initialOwnerQuery,
variables: { variables: {
statecode: 0, statecode: 0,
fullName: FullName, domainname,
}, },
}), }),
CrmService.crmgqlquery(optionsQuery), CrmService.crmgqlquery(optionsQuery),
CrmService.crmgqlquery(staticDataQuery), CrmService.crmgqlquery(staticDataQuery),
CrmService.crmgqlquery({ CrmService.crmgqlquery({
...systemUserQuery, ...systemUserQuery,
variables: { username: `${DomainName}\\${UserName}` }, variables: { domainname },
}), }),
CrmService.crmgqlquery(insuranceQuery), CrmService.crmgqlquery(insuranceQuery),
]) ])

View File

@ -2,8 +2,8 @@ import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
const query = gql` const query = gql`
query($statecode: Int, $fullName: String) { query($statecode: Int, $domainname: String) {
selectLead: leads(statecode: $statecode, owner_domainname: $fullName) { selectLead: leads(statecode: $statecode, owner_domainname: $domainname) {
customerid customerid
leadid leadid
fullname fullname
@ -15,7 +15,7 @@ const query = gql`
} }
selectOpportunity: opportunities( selectOpportunity: opportunities(
statecode: $statecode statecode: $statecode
owner_domainname: $fullName owner_domainname: $domainname
) { ) {
opportunityid opportunityid
name name

View File

@ -2,8 +2,8 @@ import { gql } from '@apollo/client';
export default { export default {
query: gql` query: gql`
query($username: String) { query($domainname: String) {
systemuser(domainname: $username) { systemuser(domainname: $domainname) {
evo_job_titleid evo_job_titleid
businessunitid businessunitid
firstname firstname

View File

@ -2,24 +2,9 @@ import axios from 'axios';
import { getServerUrl } from 'client/common/urls'; import { getServerUrl } from 'client/common/urls';
import { CORE_PROXY_URL } from 'core/constants/urls'; import { CORE_PROXY_URL } from 'core/constants/urls';
import { IPreparedData } from 'core/types/Calculation/Requests'; import { IPreparedData } from 'core/types/Calculation/Requests';
import { import { IGetCalculationResponse } from 'core/types/Calculation/Responses';
IGetCalculationResponse,
IGetUserResponse,
} from 'core/types/Calculation/Responses';
export default class { export default class {
static getUser = (): Promise<IGetUserResponse> =>
new Promise((resolve, reject) => {
axios
.get('/api/users/getUser')
.then(res => {
resolve(res.data);
})
.catch(err => {
reject(err);
});
});
static calculate = ( static calculate = (
preparedData: IPreparedData, preparedData: IPreparedData,
): Promise<IGetCalculationResponse> => ): Promise<IGetCalculationResponse> =>

View File

@ -30,7 +30,7 @@ export default async () => {
preparedPayments, preparedPayments,
} = calculationRes; } = calculationRes;
const domainName = (await getUser()).FullName || ''; const { domainname } = getUser();
// if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
console.log('domainName', domainName); console.log('domainName', domainName);
console.log('values', values); console.log('values', values);
@ -41,7 +41,7 @@ export default async () => {
// } // }
CrmService.createKp({ CrmService.createKp({
domainName, domainName: domainname,
calculation: { calculation: {
insurances, insurances,
preparedValues, preparedValues,

View File

@ -1,26 +1,23 @@
import { User } from 'core/types/user'; import { User } from 'core/types/user';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
function getUserObj(user: User) {
return {
...user,
fullname: `${user.domainname}\\${user.username}`,
};
}
export const getUser = (): User => { export const getUser = (): User => {
const { username, domainname } = Cookies.get(); let { username, domain } = Cookies.get();
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
if (!username || !domainname) { if (!username || !domain) {
const username = prompt('Enter username'); username = prompt('Enter username');
const domainname = prompt('Enter domainname'); domain = prompt('Enter domain');
if (username && domainname) { if (username && domain) {
Cookies.set('username', username); Cookies.set('username', username);
Cookies.set('domainname', domainname); Cookies.set('domain', domain);
} }
} }
} }
const user: User = getUserObj({ username, domainname }); const user: User = {
username,
domain,
domainname: `${domain}\\${username}`,
};
return user; return user;
}; };

View File

@ -1,2 +0,0 @@
export const domainName = 'EVOLEASING';
export const LDAP_URL = 'ldap://evoleasing.ru';

View File

@ -1,7 +1,6 @@
import { User } from 'core/types/user';
import { TCRMEntity } from '../Entities/crmEntities'; import { TCRMEntity } from '../Entities/crmEntities';
import { TEntities } from '../Entities/crmEntityNames'; import { TEntities } from '../Entities/crmEntityNames';
import { IColumn, PostValues, ColumnsNames } from './Core'; import { ColumnsNames, IColumn, PostValues } from './Core';
export interface IGetCRMEntitiesResponse { export interface IGetCRMEntitiesResponse {
entities: TEntities<TCRMEntity | TCRMEntity[]>; entities: TEntities<TCRMEntity | TCRMEntity[]>;
@ -11,7 +10,3 @@ export interface IGetCalculationResponse {
columns: { [column in ColumnsNames]?: IColumn }; columns: { [column in ColumnsNames]?: IColumn };
postValues: PostValues; postValues: PostValues;
} }
export interface IGetUserResponse {
user: User;
}

View File

@ -1,5 +1,5 @@
export type User = { export type User = {
domainname?: string; domain?: string;
username?: string; username?: string;
fullname?: string; domainname?: string;
}; };

View File

@ -1,12 +0,0 @@
import { Request, Response } from 'express';
class UsersController {
static getUser = async (req: Request, res: Response): Promise<void> => {
res.send({
//@ts-ignore
user: req.ntlm,
});
};
}
export default UsersController;

View File

@ -1 +0,0 @@
export default [];

View File

@ -1,57 +1,18 @@
import bodyParser from 'body-parser';
import compression from 'compression';
import cors from 'cors'; import cors from 'cors';
import express from 'express'; import express from 'express';
import ntlm from 'express-ntlm';
import helmet from 'helmet';
import morgan from 'morgan';
import path from 'path';
import 'reflect-metadata';
import { SERVER_PORT } from './../core/constants/urls'; import { SERVER_PORT } from './../core/constants/urls';
import { domainName, LDAP_URL } from './../core/constants/domain';
import routes from './routes'; import routes from './routes';
const isDevelopmentMode = process.env.NODE_ENV === 'development';
const app = express(); const app = express();
/** AUTHENTICATION */
if (!isDevelopmentMode)
app.use(
ntlm({
domain: domainName,
domaincontroller: LDAP_URL,
}),
);
/** AUTHENTICATION */
/**EXTENTIONS */ /**EXTENTIONS */
app.use(cors({ origin: isDevelopmentMode && '*' })); app.use(cors({ origin: process.env.NODE_ENV === 'development' && '*' }));
app.use(helmet({ contentSecurityPolicy: { reportOnly: true } }));
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
}),
);
app.use(compression());
app.use(morgan(isDevelopmentMode ? 'dev' : 'tiny'));
/**EXTENTIONS */ /**EXTENTIONS */
/**ROUTES */ /**ROUTES */
app.use('/', routes); app.use('/', routes);
/**ROUTES */ /**ROUTES */
/**CLIENT */
if (!isDevelopmentMode) {
const root_dir = path.resolve('build');
app.use(express.static(root_dir));
app.get('*', function (req, res) {
res.sendFile('index.html', { root: root_dir });
});
}
/**CLIENT */
app.listen(SERVER_PORT, () => { app.listen(SERVER_PORT, () => {
console.log('ENV: ', process.env.NODE_ENV); console.log('ENV: ', process.env.NODE_ENV);
console.log(`Server now listening on port: ${SERVER_PORT}`); console.log(`Server now listening on port: ${SERVER_PORT}`);

View File

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

View File

@ -1,8 +0,0 @@
import UsersController from "../controllers/UsersController";
import { Router } from "express";
const router = Router();
router.get("/getUser", UsersController.getUser);
export default router;

View File

@ -1,6 +1,5 @@
const path = require('path'); const path = require('path');
const nodeExternals = require('webpack-node-externals'); const nodeExternals = require('webpack-node-externals');
const dotenv = require('dotenv-webpack');
module.exports = { module.exports = {
mode: process.env.NODE_ENV || 'development', mode: process.env.NODE_ENV || 'development',
@ -37,5 +36,4 @@ module.exports = {
}, },
], ],
}, },
plugins: [new dotenv()],
}; };