forked from jitesh-kusalkar/tech-stash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (42 loc) · 1.45 KB
/
app.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
'use strict';
var express = require('express');
var app = express();
var cors = require('cors');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var jwt = require('express-jwt');
const APP_PORT = 3000;
// Model export
var User = require('./models/user');
//var UserActivity = require('./models/user-activity');
var Group = require('./models/group');
var Post = require('./models/post');
// Initializing auth token
var auth = jwt({
secret: 'VERA_VERTO', // Move this to env file
userProperty: 'payload'
});
// Routes
var userRouter = require('./route/user.route')(User, express, bodyParser, auth);
//var userActivityRouter = require('./route/user-activity.route')(UserActivity, express, bodyParser);
var postRouter = require('./route/post.route')(Post, Group, User, express, bodyParser, auth);
var groupRouter = require('./route/group.route')(Group, express, bodyParser, auth);
// Connect to Mongoose
mongoose.connect('mongodb://localhost/techstash');
var db = mongoose.connection;
app.use(cors());
app.use(function (err, req, res, next) {
if (err.name === 'UnauthorizedError') {
res.status(401);
res.json({ message: err.name + ": " + err.message });
}
});
// All APIs goes below
// GET
app.use('/api/user', userRouter);
//app.use('/api/user/activity', userActivityRouter);
app.use('/api/post', postRouter);
app.use('/api/group', groupRouter);
// End
app.listen(APP_PORT);
console.log('App listening @ ', APP_PORT);