-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
125 lines (92 loc) · 2.74 KB
/
server.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
var logger = require('morgan');
var favicon = require('serve-favicon');
var cookieParser=require('cookie-parser');
var session=require('express-session');
var passport=require('passport');
var expressValidator=require('express-validator');
var flash=require('connect-flash');
var session = require('express-session');
var LocalStrategy=require('passport-local');
var multer=require('multer');
// Get our API routes
const api = require('./server/api');
const users = require('./server/users');
const child = require('./server/child');
const clinic = require('./server/clinic');
const app=express();
//handle File Uploads
var upload = multer({ dest: './uploads' });
// Parsers for POST data
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({
secret:'secret',
saveUninitialized:true,
resave:true
}))
app.use(cookieParser());
//middleware for express
//view Engine
app.set('views', path.join(__dirname, 'dist'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('json spaces', 40);
//passport saveUninitializ
app.use(passport.initialize());
app.use(passport.session());
// In this example, the formParam value is going to get morphed into form body format useful for printing.
app.use(expressValidator({
errorFormatter: function(param, msg, value) {
var namespace = param.split('.')
, root = namespace.shift()
, formParam = root;
while(namespace.length) {
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
//connect flash
app.use(flash());
//Global var
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
res.locals.success_msg=req.flash('Success_msg');
res.locals.error_msg=req.flash('error_msg');
res.locals.error=req.flash('error');
next();
});
// Set our api routes
app.use('/api', api);
app.use('/users', users);
app.use('/child', child);
app.use('/clinic', clinic);
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));