This repository was archived by the owner on Jul 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
80 lines (61 loc) · 2.59 KB
/
Copy pathserver.js
File metadata and controls
80 lines (61 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const express = require('express');
const bodyParser = require('body-parser');
const expressValidator = require('express-validator');
const path = require('path');
const config = require('./config');
const app = express();
const auth = require('./app/auth');
const auth_controller = require('./app/auth/auth_controller');
const task = require('./app/task');
// const product = require('./app/product'); // Imports routes for the products
// const mysql = require('mysql');
// const morgan = require('morgan');
// const rfs = require('rotating-file-stream');
// const mongoose = require('mongoose');
if(process.env.pro){
config.env = 'pro';
}
//set secret
app.set('Secret', config.secret);
// Set up mongoose connection
// mongoose.connect(config.env === 'dev' ? config.mongo.dev.url : config.mongo.dev.url);
// mongoose.Promise = global.Promise;
// let db = mongoose.connection;
// db.on('error', console.error.bind(console, 'MongoDB connection error:'));
// Set up Mysql connection
// global.connection = mysql.createConnection(config.env === 'dev' ? config.mysql.dev : config.mysql.pro);
// connection.connect();
// setInterval(function () {
// global.connection.query('SELECT 1');
// }, 5000);
//Making /public folder static (/public will be the root of all files inside public)
app.use(express.static(__dirname + '/public'));
// // create a rotating write stream
// var accessLogStream = rfs('access.log', {interval: '1d', path: path.join(__dirname, 'log/non_crash') });
// var withCrashAccessLogStream = rfs('access.log', {interval: '1d', path: path.join(__dirname, 'log/with_crash') });
// // setup the logger
// app.use(morgan('combined', { stream: accessLogStream }));
// app.use(morgan('combined', { stream: withCrashAccessLogStream, immediate: true }));
//Validation middleware
app.use(expressValidator());
//Converting body into json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//CORS related settings
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//Using routers from multiple files and folders
app.use('/auth', auth);
app.use('/task', task);
// app.use('/product', auth_controller.check, product);
// app.use('/pdf', auth_controller.check, pdf);
// app.use('/template', auth_controller.check, template);
// app.use('/printer', auth_controller.check, printer);
let port = 1234;
app.listen(port, () => {
console.log('Server is up and running on port numner ' + port);
console.log('Production Mode ', process.env.pro);
});