-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
76 lines (60 loc) · 2.11 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
const express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
logger = require('morgan'),
mongoose = require('mongoose'),
config = require('./db/config'),
User = require('./api/models/User'),
School = require('./api/models/Schools'),
Class = require('./api/models/Classes'),
Page = require('./api/models/Page'),
Job = require('./api/models/Job'),
Review = require('./api/models/Review'),
PagesSeed = require('./db/pagesSeed.json');
require('dotenv').config();
mongoose.connect(config.database);
mongoose.connection.on('connected', () => {
console.log('Connected to DB', config.database);
Page.find({}, (err, pages)=> {
if(pages.length<=0){
let pagesArray = [];
for(let page in PagesSeed){
let { pageContent, pageTitle } = PagesSeed[page];
PagesSeed[page].pageContent = JSON.stringify(pageContent);
pagesArray.push(PagesSeed[page]);
}
Page.insertMany(pagesArray);
}
});
});
mongoose.connection.on('error', err => {
console.log('Database error', err);
});
const app = express(),
server = require('http').Server(app),
port = process.env.PORT || 3001;
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use(logger('dev'));
app.use(express.static('public'));
server.listen(port, () => {
console.log(`Dont listen to my port ${port}`);
});
app.use(express.static('public'));
const userRoutes = require('./api/routes/userRoutes');
app.use('/api/user', userRoutes);
const schoolRoutes = require('./api/routes/schoolRoutes');
app.use('/api/schools', schoolRoutes);
const classesRoutes = require('./api/routes/classRoutes');
app.use('/api/classes', classesRoutes);
const pageRoutes = require('./api/routes/pageRoutes');
app.use('/api/page', pageRoutes);
const jobRoutes = require('./api/routes/jobRoutes');
app.use('/api/careers', jobRoutes);
const reviewRoutes = require('./api/routes/reviewRoutes');
app.use('/api/reviews', reviewRoutes);
// app.get('/*', (req, res, next) => {
// console.log('WILD CARD HIT------>')
// res.sendFile(path.join(__dirname, 'public', 'index.html'));
// next();
// });