-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
101 lines (81 loc) · 2.12 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var datejs = require('safe_datejs');
var Hapi = require("hapi");
var hapiAuthJWT = require('hapi-auth-jwt2');
var hapiCorsHeaders = require('hapi-cors-headers');
var mongoose = require('mongoose');
var argv = require('minimist')(process.argv.slice(2));
var net = require('net');
const Fs = require('fs');
const Url = require('url');
var connectionString = 'mongodb://localhost:27017/SMSGateway';
mongoose.connect(connectionString);
var applicationRouter = require("./routers/app").ApplicationRouter;
var paymentRouter = require("./routers/payment").PaymentRouter;
var applicationController = require("./controller/app").ApplicationController;
var modules = require('./module/modules').Modules;
modules().reloadModules(function(sms){
});
'use strict';
var cors = {
origin: ['*'],
headers: ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version', 'X-Requested-With'],
}
const server = new Hapi.Server({
connections: {
routes: {
cors: cors
}
}
});
var host = '0.0.0.0';
var port = 6060;
if('h' in argv) {
host = String(argv.h);
}
if('p' in argv) {
port = Number(argv.p);
}
const config = {
https: {
port: 6063,
key: Fs.readFileSync('zarforosh.ir_key.key'),
cert: Fs.readFileSync('zarforosh.ir_bundle_.crt')
}
}
server.connection({
host: host,
port: port
});
server.connection({
host: host,
port: config.https.port,
tls: {
key: config.https.key,
cert: config.https.cert
}
});
server.register(hapiAuthJWT, function (err) {
if (err) {
console.log(err);
}
server.auth.strategy('jwt', 'jwt', true,
{
key: '729183456258456',
validateFunc: applicationController().validate,
verifyOptions: { ignoreExpiration: true }
});
});
server.register(require('inert'), function(err){
if (err) {
consle.log(err);
}
});
server.ext('onPreResponse', hapiCorsHeaders);
applicationRouter().register(server);
paymentRouter().register(server);
server.start(function (err) {
if (err) {
throw err;
}
console.log('Server running at:', server.info);
})