-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
67 lines (48 loc) · 1.75 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// express app
var express = require('express');
var app = express();
// setup logger for dev env
var logger = require('morgan');
app.use(logger('dev'));
// load dotenv
var dotenv = require('dotenv');
dotenv.load();
// parse application/json
var bodyParser = require('body-parser');
app.use(bodyParser.json());
// authentication with passport
var passport = require('passport');
require('./config/passport')(passport);
app.use(passport.initialize());
// database
var mongoose = require('mongoose');
var database = require('./config/database');
mongoose.connect(database.url);
// mount express static assets folder
app.use(express.static(__dirname + '/public'));
// setup CORS headers before mounting routes
app.all('/*', [require('./middlewares/setCors')]);
// mount express routes
// allow signin signup without authentication
var sessions = require('./routes/sessions');
app.use('/api', sessions);
// we process all other requests to /api/ requesting a valid token
app.all('/api/*', [require('./middlewares/validateRequest')]);
var bars = require('./routes/bars');
app.use('/api/bars', bars);
var posts = require('./routes/posts');
app.use('/api/bars', posts);
var votes = require('./routes/votes');
app.use('/api/votes', votes);
var reviews = require('./routes/reviews');
app.use('/api/bars', reviews);
var checkins = require('./routes/checkins');
app.use('/api/checkins', checkins);
var settings = require('./routes/settings');
app.use('/api/users', settings);
var crawls = require('./routes/crawls');
app.use('/api/crawls', crawls);
// error handler if no route matches
require('./config/error-handler')(app);
// make express app available to be launched from another file
module.exports = app;