2020-11-22 15:42:17 +00:00
|
|
|
/**
|
|
|
|
* Required External Modules
|
|
|
|
*/
|
|
|
|
|
2020-11-29 12:05:25 +00:00
|
|
|
import * as dotenv from 'dotenv';
|
|
|
|
import express from 'express';
|
|
|
|
import cors from 'cors';
|
|
|
|
import helmet from 'helmet';
|
|
|
|
import {productsRouter} from './models/products/products.router';
|
|
|
|
import {categoriesRouter} from './models/categories/categories.router';
|
|
|
|
import {manufacturersRouter} from './models/manufacturers/manufacturers.router';
|
|
|
|
import {pricesRouter} from './models/prices/prices.router';
|
|
|
|
import {vendorsRouter} from './models/vendors/vendors.router';
|
|
|
|
import {errorHandler} from './middleware/error.middleware';
|
|
|
|
import {notFoundHandler} from './middleware/notFound.middleware';
|
2021-04-29 07:42:34 +00:00
|
|
|
import {usersRouter} from './models/users/users.router';
|
2020-11-22 15:42:17 +00:00
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* App Variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!process.env.PORT) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PORT: number = parseInt(process.env.PORT as string, 10);
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* App Configuration
|
|
|
|
*/
|
|
|
|
|
|
|
|
app.use(helmet());
|
|
|
|
app.use(cors());
|
|
|
|
app.use(express.json());
|
2020-11-29 12:05:25 +00:00
|
|
|
app.use('/products', productsRouter);
|
|
|
|
app.use('/categories', categoriesRouter);
|
|
|
|
app.use('/manufacturers', manufacturersRouter);
|
|
|
|
app.use('/prices', pricesRouter);
|
2021-04-29 07:42:34 +00:00
|
|
|
app.use('/users', usersRouter);
|
2020-11-29 12:05:25 +00:00
|
|
|
app.use('/vendors', vendorsRouter);
|
2020-11-22 15:42:17 +00:00
|
|
|
|
2020-11-24 23:38:16 +00:00
|
|
|
app.use(errorHandler);
|
|
|
|
app.use(notFoundHandler);
|
|
|
|
|
2020-11-22 15:42:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Server Activation
|
|
|
|
*/
|
|
|
|
|
|
|
|
const server = app.listen(PORT, () => {
|
|
|
|
console.log(`Listening on port ${PORT}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Webpack HMR Activation
|
|
|
|
*/
|
|
|
|
|
|
|
|
type ModuleId = string | number;
|
|
|
|
|
|
|
|
interface WebpackHotModule {
|
|
|
|
hot?: {
|
|
|
|
data: any;
|
|
|
|
accept(
|
|
|
|
dependencies: string[],
|
|
|
|
callback?: (updatedDependencies: ModuleId[]) => void,
|
|
|
|
): void;
|
|
|
|
accept(dependency: string, callback?: () => void): void;
|
|
|
|
accept(errHandler?: (err: Error) => void): void;
|
|
|
|
dispose(callback: (data: any) => void): void;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
declare const module: WebpackHotModule;
|
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept();
|
|
|
|
module.hot.dispose(() => server.close());
|
|
|
|
}
|