Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
92 lines (76 loc) · 2.29 KB
/
Copy pathapp.js
File metadata and controls
92 lines (76 loc) · 2.29 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
81
82
83
84
85
86
87
88
89
90
91
92
// import modules
const express = require("express");
const session = require("express-session");
const path = require("path");
const bodyParser = require("body-parser");
const socket = require("socket.io");
const passport = require("passport");
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const mongoose = require("mongoose");
const MongoStore = require("connect-mongo")(session);
const cors = require("cors");
const webpackConfig = require("./webpack.config");
const app = express();
// const bootStrap = require('./server/modules/bootStrap');
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, './server/views'));
app.use(express.static(path.join(__dirname, 'public')));
// connect to mongoDB
mongoose.connect(
'mongodb://localhost/tinyKindness',
{ useNewUrlParser: true },
(err) => {
if (err) throw err;
else {
console.log('connected to mongodb');
// bootStrap.init();
}
},
);
app.use(cors());
// Path for images
app.use('/images', express.static(path.join(__dirname, '/client/src/images')));
// initialize session
app.use(
session({
secret: 'tinyKindness',
resave: true,
saveUninitialized: true,
store: new MongoStore({ url: 'mongodb://localhost/tinyKindness-session' })
})
);
// Webpack config
if (process.env.NODE_ENV === 'development') {
console.log('in webpack hot middleware');
const compiler = webpack(webpackConfig);
app.use(
webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
})
);
}
// Initialize passport
app.use(passport.initialize());
require("./server/modules/passport")(passport);
// use passport as middleware
// use cors
app.use(cors());
// Essential Middleware
app.use(bodyParser.json());
// Requiring routes
app.use('/api/v1', require('./server/routers/api'));
app.use(require('./server/routers/index'));
// listen app on 8001 port
const server = app.listen(8001, () => {
console.log('Server is running on http://localhost:8001');
});
const io = socket(server);
const tagsController = require('./server/controllers/tag.controller');
io.on('connection', (client) => {
client.on('getTags', async (data) => {
const tags = await tagsController.sendTags(data);
io.emit('sendTags', tags);
});
});