63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import bodyParser from 'body-parser';
|
|
import compression from 'compression';
|
|
import cors from 'cors';
|
|
// import cookieParser from "cookie-parser";
|
|
import express from 'express';
|
|
import helmet from 'helmet';
|
|
import morgan from 'morgan';
|
|
import path from 'path';
|
|
import 'reflect-metadata';
|
|
import routes from './routes';
|
|
import ntlm from 'express-ntlm';
|
|
import { SERVER_PORT } from './../core/constants/urls';
|
|
|
|
const isDevelopmentMode = process.env.NODE_ENV === 'development';
|
|
|
|
const buildDir = path.join(
|
|
process.cwd(),
|
|
process.env.NODE_ENV === 'development' ? '/build' : '',
|
|
);
|
|
|
|
const app = express();
|
|
|
|
app.use(cors({ origin: isDevelopmentMode && '*', credentials: false }));
|
|
/** AUTHENTICATION */
|
|
if (!isDevelopmentMode)
|
|
app.use(
|
|
ntlm({
|
|
domain: 'EVOLEASING',
|
|
domaincontroller: 'ldap://evoleasing.ru',
|
|
}),
|
|
);
|
|
/** AUTHENTICATION */
|
|
|
|
/**EXTENTIONS */
|
|
app.use(bodyParser.json());
|
|
app.use(
|
|
bodyParser.urlencoded({
|
|
extended: true,
|
|
}),
|
|
);
|
|
app.use(helmet({ contentSecurityPolicy: { reportOnly: true } }));
|
|
|
|
// app.use(cookieParser());
|
|
app.use(compression());
|
|
app.use(morgan(isDevelopmentMode ? 'dev' : 'tiny'));
|
|
/**EXTENTIONS */
|
|
|
|
/**ROUTES */
|
|
app.use('/', routes);
|
|
/**ROUTES */
|
|
|
|
/**CLIENT */
|
|
app.use(express.static(buildDir));
|
|
app.get('*', function (req, res) {
|
|
res.sendFile(path.join(buildDir, 'index.html'));
|
|
});
|
|
/**CLIENT */
|
|
|
|
console.log('checking port', SERVER_PORT);
|
|
app.listen(SERVER_PORT, () => {
|
|
console.log(`Server now listening on port: ${SERVER_PORT}`);
|
|
});
|