forked from jsiochi/GeoBadges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (36 loc) · 1.49 KB
/
index.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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var mongoose = require('mongoose');
var db = require('./config/db');
var credlyRoutes = require('./routes/credly');
var pathwayRoutes = require('./routes/pathways');
var port = process.env.PORT || 8080;
//need to add app.use for other dependencies
app.use(bodyParser.json());
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(express.static(__dirname + '/public'));
//db connection
mongoose.connect(db.url);
var badgedb = mongoose.connection;
badgedb.once('open', function (callback) {
console.log('db connection successful');
});
//routes
var router = express.Router();
//api routes
//should use middleware for validation and auth. NEED THIS SOON (ish)
router.get('/api/pathways', pathwayRoutes.getPathways);
router.get('/api/pathway/:pathway_id', pathwayRoutes.getPathwayById);
router.post('/api/pathways', pathwayRoutes.createPathway);
router.put('/api/pathway/:pathway_id', pathwayRoutes.updatePathway);
router.post('/api/credlybadge', credlyRoutes.createBadge);
router.put('/api/credlybadge/:badge_id', credlyRoutes.updateBadge);
router.get('/api/credlybadge/:badge_id', credlyRoutes.getBadge);
app.use('/', router);
app.listen(port);
console.log('Listening... can you hear it? port ' + port);
exports = module.exports = app;