-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (70 loc) · 3.5 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
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
// server.js
// BASE SETUP
// =============================================================================
// load config
var config = require('./config');
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// DATABASE CONNECTION
// =============================================================================
var connstr = undefined;
// Check for Docker linked container
if (process.env.DB_PORT_27017_TCP_ADDR && process.env.DB_PORT_27017_TCP_PORT) {
connstr = `mongodb://${process.env.DB_PORT_27017_TCP_ADDR}:${process.env.DB_PORT_27017_TCP_PORT}/mobyourlife`;
}
mongoose.connect(connstr || process.env.MONGOLAB_CONNECTION || config.api.database);
// ENABLE CORS
// =============================================================================
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE");
next();
});
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// LOAD CONTROLLERS
var domain = require('./controllers/domain');
var profile = require('./controllers/profile');
var feeds = require('./controllers/feeds');
var fotos = require('./controllers/fotos');
var videos = require('./controllers/videos');
var carousel = require('./controllers/carousel');
var textpages = require('./controllers/textpages');
var outmail = require('./controllers/outmail');
var albumpages = require('./controllers/albumpages');
var albums = require('./controllers/albums');
// REGISTER OUR ROUTES -------------------------------
router.get('/api/domain/:name', domain.getDomain);
// Basic pages --------------------------------------
router.get('/api/:fansite/profile', profile.getProfile);
router.get('/api/:fansite/feeds', feeds.getFeeds);
router.get('/api/:fansite/fotos', fotos.getFotos);
router.get('/api/:fansite/videos', videos.getVideos);
router.get('/api/:fansite/carousel', carousel.getCarousel);
// Text pages --------------------------------------
router.get('/api/:fansite/textpages', textpages.getTextPages);
router.get('/api/:fansite/textpages/:path', textpages.getPageBody);
router.post('/api/:fansite/textpages', textpages.newTextPage);
router.post('/api/:fansite/textpages/:pageid', textpages.editTextPage);
router.delete('/api/:fansite/textpages/:pageid', textpages.deleteTextPage);
// Albums --------------------------------------
router.get('/api/:fansite/albumpages', albumpages.getAlbumPages);
router.get('/api/:fansite/albums', albums.getAlbums);
router.get('/api/:fansite/albums/:albumid', albums.getAlbum);
router.post('/api/:fansite/albums/:albumid', albums.setAlbumType);
// Outmail --------------------------------------
router.post('/api/:fansite/outmail', outmail.postNewMail);
// START THE SERVER
// =============================================================================
app.use(router);
app.listen(config.api.port);
console.log('API listening on port ' + config.api.port);