-
Notifications
You must be signed in to change notification settings - Fork 0
/
_index.js
154 lines (135 loc) · 3.98 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
/**
* @license
* Copyright SOAJS All Rights Reserved.
*
* Use of this source code is governed by an Apache license that can be
* found in the LICENSE file at the root of this repository
*/
const soajs = require('soajs');
let config = require('./config.js');
config.packagejson = require("./package.json");
const lib = require("./lib.js");
const service = new soajs.server.service(config);
function checkIfError(req, res, data, cb) {
return data.check ? res.json(req.soajs.buildResponse({code: data.code, msg: data.error})) : cb();
}
function run(serviceStartCb) {
service.init(() => {
//https://api.soajs.org/soajsorg/...
service.post("/soajsorg/sendMessage", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, 'New Email from SOAJS Website', 'message', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
service.post("/soajsorg/sendProject", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, 'New Project from SOAJS Website', 'project', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
service.post("/soajsorg/sendContribute", (req, res) => {
let data = req.soajs.inputmaskData;
data.product = data.product.join(" - ");
lib.sendMail(req, res, data, 'New Contributor from SOAJS Website', 'contribute', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
//https://api.herrontech.com/herrontech/contact
service.post("/herrontech/contact", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, "New Email from Herron Tech Website", 'herrontech_contact', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
//https://api.soajs.io/io/...
service.post("/io/sendMessage", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, "New Email from SOAJS.io", 'io_contact', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
service.post("/io/sendRequest", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, "New Demo Request from SOAJS.io", 'io_demo', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
service.post("/io/subscribe", (req, res) => {
let data = req.soajs.inputmaskData;
lib.sendMail(req, res, data, "New Subscription to SOAJS.io Newsletter", 'io_subscribe', (error) => {
let data = {
"check": error,
"code": 401,
"error": config.errors[401]
};
checkIfError(req, res, data, () => {
return res.json(req.soajs.buildResponse(null, true));
});
});
});
service.start(serviceStartCb);
});
}
function stop(serviceStopCb) {
service.stop(serviceStopCb);
}
module.exports = {
"runService": (serviceStartCb) => {
if (serviceStartCb && typeof serviceStartCb === "function") {
run(serviceStartCb);
} else {
run(null);
}
},
"stopService": (serviceStopCb) => {
if (serviceStopCb && typeof serviceStopCb === "function") {
stop(serviceStopCb);
} else {
stop(null);
}
}
};