-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
80 lines (64 loc) · 2.85 KB
/
server.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
var express = require( 'express' );
var bodyParser = require('body-parser')
var mongoose = require( 'mongoose' );
var dotenv = require( 'dotenv' );
//var azure = require( 'azure' ); -> because Azure was not working with the certificate
var apn = require('apn');
// Load environment variables from .env file
dotenv.load();
// Controllers
var mainController = require( './controllers/main' );
var profileController = require( './controllers/profile' );
var setupController = require( './controllers/setup' );
var productController = require( './controllers/product' );
var questionController = require( './controllers/question' );
var answerController = require( './controllers/answer' );
var ratingController = require( './controllers/rating' );
// Connect to mongodb
mongoose.connect( process.env.MONGODB );
mongoose.connection.on( 'error', ( err ) => {
console.log( 'MongoDB Connection Error. Please make sure that MongoDB is running. ' + process.env.MONGODB );
console.log( err );
process.exit( 1 );
} );
// express
var app = express( );
// add express middleware
app.use( bodyParser.json( ) ); // for parsing application/json
// set express port
app.set( 'port', process.env.PORT || 3000 );
// setup Azure Notification Hub service
// notificationHubService = azure.createNotificationHubService( process.env.AZURE_HUB_NAME, process.env.AZURE_HUB_CONNECTION_STRING );
apnProvider = new apn.Provider( {
key: process.env.APN_PUSH_KEY_PATH,
cert: process.env.APN_PUSH_CERT_PATH,
passphrase: process.env.APN_PUSH_PHRASE,
production: ( process.env.APN_PUSH_ENV === 'production' ? true : false )
} );
// API
app.get( '/', mainController.index );
app.get( '/api/v1/fakedata', setupController.getFakeData );
app.get( '/api/v1/dropall', setupController.getDropAll );
// user profile
app.get( '/api/v1/profiles', profileController.getProfiles );
app.get( '/api/v1/profile/:id', profileController.getProfile );
app.post( '/api/v1/profile', profileController.postProfile );
app.put( '/api/v1/profile/:id', profileController.putProfile );
// product
app.post( '/api/v1/product', productController.postProductDetails );
app.get( '/api/v1/products', productController.getProducts );
// question
app.get( '/api/v1/questions', questionController.getQuestions );
app.get( '/api/v1/question/:id', questionController.getQuestion );
app.get( '/api/v1/question/:id/status', questionController.getQuestionStatus );
app.post( '/api/v1/question', questionController.postQuestion );
// answer
app.get( '/api/v1/answers', answerController.getAnswers );
app.post( '/api/v1/answer', answerController.postAnwser );
// rating
app.get( '/api/v1/ratings', ratingController.getRatings );
app.get ( '/api/v1/demo', setupController.demoProducts );
// Start express and listen to port ( default: 3000 )
app.listen( app.get( 'port' ), () => {
console.log( 'Express server listening on port ' + app.get( 'port' ) );
} );