server is only for dev & fix getUser
This commit is contained in:
parent
f1191811ae
commit
4e0e0de5fb
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,6 +13,7 @@
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
@ -25,3 +26,4 @@ yarn.lock
|
||||
*.log
|
||||
package-lock.json
|
||||
/.vscode
|
||||
.eslintcache
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
FROM node:14-alpine as builder
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV REACT_APP_CRM=prod
|
||||
ENV GENERATE_SOURCEMAP=false
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
@ -2,8 +2,6 @@ version: '3.3'
|
||||
services:
|
||||
auth:
|
||||
build: ./EvoCalculator.Auth
|
||||
ports:
|
||||
- '8888:8888'
|
||||
networks:
|
||||
- calc_network
|
||||
restart: always
|
||||
@ -25,6 +23,8 @@ services:
|
||||
proxy:
|
||||
restart: always
|
||||
build: ./EvoCalculator.Proxy
|
||||
environment:
|
||||
- CRM_URL=http://...
|
||||
ports:
|
||||
- '4000:80'
|
||||
networks:
|
||||
|
||||
40
package.json
40
package.json
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "evo_calculator",
|
||||
"name": "evocalculator.client",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.3.4",
|
||||
@ -9,29 +9,16 @@
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"@types/graphql": "^14.5.0",
|
||||
"antd": "^4.9.2",
|
||||
"axios": "^0.21.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"class-validator": "^0.12.2",
|
||||
"compression": "^1.7.4",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"antd": "^4.9.4",
|
||||
"axios": "^0.21.1",
|
||||
"cors": "^2.8.5",
|
||||
"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",
|
||||
"helmet": "^4.2.0",
|
||||
"js-cookie": "^2.2.1",
|
||||
"lodash": "^4.17.20",
|
||||
"luxon": "^1.25.0",
|
||||
"mobx": "^6.0.4",
|
||||
"mobx-react-lite": "^3.1.6",
|
||||
"morgan": "^1.10.0",
|
||||
"normalize.css": "^8.0.1",
|
||||
"pluralize": "^8.0.0",
|
||||
"react": "^17.0.1",
|
||||
@ -39,50 +26,47 @@
|
||||
"react-router": "^5.2.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "^4.0.1",
|
||||
"recompose": "^0.30.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"styled-components": "^5.2.1",
|
||||
"styled-system": "^5.1.5",
|
||||
"ts-loader": "^8.0.11",
|
||||
"typescript": "4.1.2",
|
||||
"ts-loader": "^8.0.12",
|
||||
"typescript": "4.1.3",
|
||||
"use-debounce": "^5.1.0",
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "^13.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/compression": "^1.7.0",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/cors": "^2.8.8",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/express-http-proxy": "^1.6.1",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/lodash": "^4.14.165",
|
||||
"@types/luxon": "^1.25.0",
|
||||
"@types/morgan": "^1.9.2",
|
||||
"@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"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "craco test",
|
||||
"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": "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": "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:server": "cross-env NODE_ENV=production webpack --config webpack.config.server.js"
|
||||
"build:server": "webpack --config webpack.config.server.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
|
||||
@ -9,21 +9,21 @@ import systemUserQuery from './queries/systemUserQuery';
|
||||
|
||||
export default () =>
|
||||
new Promise((resolve, reject) => {
|
||||
const { username: UserName, domainname: DomainName, FullName } = getUser();
|
||||
const { domainname } = getUser();
|
||||
|
||||
Promise.all([
|
||||
CrmService.crmgqlquery({
|
||||
...initialOwnerQuery,
|
||||
variables: {
|
||||
statecode: 0,
|
||||
fullName: FullName,
|
||||
domainname,
|
||||
},
|
||||
}),
|
||||
CrmService.crmgqlquery(optionsQuery),
|
||||
CrmService.crmgqlquery(staticDataQuery),
|
||||
CrmService.crmgqlquery({
|
||||
...systemUserQuery,
|
||||
variables: { username: `${DomainName}\\${UserName}` },
|
||||
variables: { domainname },
|
||||
}),
|
||||
CrmService.crmgqlquery(insuranceQuery),
|
||||
])
|
||||
|
||||
@ -2,8 +2,8 @@ import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
const query = gql`
|
||||
query($statecode: Int, $fullName: String) {
|
||||
selectLead: leads(statecode: $statecode, owner_domainname: $fullName) {
|
||||
query($statecode: Int, $domainname: String) {
|
||||
selectLead: leads(statecode: $statecode, owner_domainname: $domainname) {
|
||||
customerid
|
||||
leadid
|
||||
fullname
|
||||
@ -15,7 +15,7 @@ const query = gql`
|
||||
}
|
||||
selectOpportunity: opportunities(
|
||||
statecode: $statecode
|
||||
owner_domainname: $fullName
|
||||
owner_domainname: $domainname
|
||||
) {
|
||||
opportunityid
|
||||
name
|
||||
|
||||
@ -2,8 +2,8 @@ import { gql } from '@apollo/client';
|
||||
|
||||
export default {
|
||||
query: gql`
|
||||
query($username: String) {
|
||||
systemuser(domainname: $username) {
|
||||
query($domainname: String) {
|
||||
systemuser(domainname: $domainname) {
|
||||
evo_job_titleid
|
||||
businessunitid
|
||||
firstname
|
||||
|
||||
@ -2,24 +2,9 @@ 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,
|
||||
IGetUserResponse,
|
||||
} from 'core/types/Calculation/Responses';
|
||||
import { IGetCalculationResponse } from 'core/types/Calculation/Responses';
|
||||
|
||||
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 = (
|
||||
preparedData: IPreparedData,
|
||||
): Promise<IGetCalculationResponse> =>
|
||||
|
||||
@ -30,7 +30,7 @@ export default async () => {
|
||||
preparedPayments,
|
||||
} = calculationRes;
|
||||
|
||||
const domainName = (await getUser()).FullName || '';
|
||||
const { domainname } = getUser();
|
||||
// if (process.env.NODE_ENV === 'development') {
|
||||
console.log('domainName', domainName);
|
||||
console.log('values', values);
|
||||
@ -41,7 +41,7 @@ export default async () => {
|
||||
// }
|
||||
|
||||
CrmService.createKp({
|
||||
domainName,
|
||||
domainName: domainname,
|
||||
calculation: {
|
||||
insurances,
|
||||
preparedValues,
|
||||
|
||||
@ -1,26 +1,23 @@
|
||||
import { User } from 'core/types/user';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
function getUserObj(user: User) {
|
||||
return {
|
||||
...user,
|
||||
fullname: `${user.domainname}\\${user.username}`,
|
||||
};
|
||||
}
|
||||
|
||||
export const getUser = (): User => {
|
||||
const { username, domainname } = Cookies.get();
|
||||
let { username, domain } = Cookies.get();
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (!username || !domainname) {
|
||||
const username = prompt('Enter username');
|
||||
const domainname = prompt('Enter domainname');
|
||||
if (username && domainname) {
|
||||
if (!username || !domain) {
|
||||
username = prompt('Enter username');
|
||||
domain = prompt('Enter domain');
|
||||
if (username && domain) {
|
||||
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;
|
||||
};
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
export const domainName = 'EVOLEASING';
|
||||
export const LDAP_URL = 'ldap://evoleasing.ru';
|
||||
@ -1,7 +1,6 @@
|
||||
import { User } from 'core/types/user';
|
||||
import { TCRMEntity } from '../Entities/crmEntities';
|
||||
import { TEntities } from '../Entities/crmEntityNames';
|
||||
import { IColumn, PostValues, ColumnsNames } from './Core';
|
||||
import { ColumnsNames, IColumn, PostValues } from './Core';
|
||||
|
||||
export interface IGetCRMEntitiesResponse {
|
||||
entities: TEntities<TCRMEntity | TCRMEntity[]>;
|
||||
@ -11,7 +10,3 @@ export interface IGetCalculationResponse {
|
||||
columns: { [column in ColumnsNames]?: IColumn };
|
||||
postValues: PostValues;
|
||||
}
|
||||
|
||||
export interface IGetUserResponse {
|
||||
user: User;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export type User = {
|
||||
domainname?: string;
|
||||
domain?: string;
|
||||
username?: string;
|
||||
fullname?: string;
|
||||
domainname?: string;
|
||||
};
|
||||
|
||||
@ -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;
|
||||
@ -1 +0,0 @@
|
||||
export default [];
|
||||
@ -1,57 +1,18 @@
|
||||
import bodyParser from 'body-parser';
|
||||
import compression from 'compression';
|
||||
import cors from 'cors';
|
||||
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 { domainName, LDAP_URL } from './../core/constants/domain';
|
||||
import routes from './routes';
|
||||
|
||||
const isDevelopmentMode = process.env.NODE_ENV === 'development';
|
||||
|
||||
const app = express();
|
||||
|
||||
/** AUTHENTICATION */
|
||||
if (!isDevelopmentMode)
|
||||
app.use(
|
||||
ntlm({
|
||||
domain: domainName,
|
||||
domaincontroller: LDAP_URL,
|
||||
}),
|
||||
);
|
||||
/** AUTHENTICATION */
|
||||
|
||||
/**EXTENTIONS */
|
||||
app.use(cors({ origin: isDevelopmentMode && '*' }));
|
||||
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'));
|
||||
app.use(cors({ origin: process.env.NODE_ENV === 'development' && '*' }));
|
||||
/**EXTENTIONS */
|
||||
|
||||
/**ROUTES */
|
||||
app.use('/', 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, () => {
|
||||
console.log('ENV: ', process.env.NODE_ENV);
|
||||
console.log(`Server now listening on port: ${SERVER_PORT}`);
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
import users from './users';
|
||||
import proxy from './proxy';
|
||||
|
||||
const routes = Router();
|
||||
|
||||
routes.use('/api/users', users);
|
||||
routes.use('/proxy', proxy);
|
||||
|
||||
export default routes;
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
import UsersController from "../controllers/UsersController";
|
||||
import { Router } from "express";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/getUser", UsersController.getUser);
|
||||
|
||||
export default router;
|
||||
@ -1,6 +1,5 @@
|
||||
const path = require('path');
|
||||
const nodeExternals = require('webpack-node-externals');
|
||||
const dotenv = require('dotenv-webpack');
|
||||
|
||||
module.exports = {
|
||||
mode: process.env.NODE_ENV || 'development',
|
||||
@ -37,5 +36,4 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [new dotenv()],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user