-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
77 lines (60 loc) · 1.79 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
68
69
70
71
72
73
74
75
76
77
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const NodeCache = require("node-cache");
const nodemailer = require("nodemailer");
const cors = require('cors');
var apn = require('apn');
// initialize express app
const app = express();
// allow cors
app.use(
cors({
origin: true,
credentials: true
})
);
// mongodb connection
mongoose.connect(
process.env.DB_LINK,
{ useNewUrlParser: true, useFindAndModify: false, autoIndex: false, useUnifiedTopology: true }
).then(() => {
console.log("MongoDB Connected")
}).catch(error => console.log(error));
mongoose.Promise = global.Promise;
// email transporter
module.exports.transporter = transporter = nodemailer.createTransport({
host: 'smtp.mailgun.org',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: process.env.email,
pass: process.env.emailPass
}
});
// connect to Apple Push Notification service
var apnOptions = {
token: {
key: process.env.ApnAuthKey,
keyId: process.env.keyId,
teamId: process.env.teamId
},
production: (process.env.apnProduction == 'true')
};
module.exports.apnProvider = new apn.Provider(apnOptions);
// cache for active auth tokens
module.exports.jwtCache = new NodeCache();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// routes
const postsRouter = require('./v1/routers/posts');
const authRouter = require('./v1/routers/auth');
const locationRouter = require('./v1/routers/location');
const notificationRouter = require('./v1/routers/notifications');
app.use('/api/v1/posts', postsRouter);
app.use('/api/v1/auth', authRouter);
app.use('/api/v1/location', locationRouter);
app.use('/api/v1/notifications', notificationRouter);
module.exports = app;