-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp copy.js
115 lines (102 loc) · 3.15 KB
/
app copy.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
/**
* Created by Michael on 11/14/2016.
*/
var soap = require('soap');
var express = require('express');
var fs = require('fs');
var https = require('https');
var auth = require('basic-auth')
var useAuth = true;
var app = express();
var compare = require('tsscmp')
// function splitter_function(args) {
// console.log('splitter_function');
// var splitter = args.splitter;
// var splitted_msg = args.message.split(splitter);
// var result = [];
// for(var i=0; i<splitted_msg.length; i++){
// result.push(splitted_msg[i]);
// }
// return {
// result: result
// }
// }
function splitter_function(args) {
console.log('splitter_function');
console.log(args.message);
return {
result: args.message
}
}
// the service
var serviceObject = {
MessageSplitterService: {
MessageSplitterServiceSoapPort: {
MessageSplitter: splitter_function
},
MessageSplitterServiceSoap12Port: {
MessageSplitter: splitter_function
}
}
};
// load the WSDL file
var xml = fs.readFileSync('service.wsdl', 'utf8');
var options = {
key: fs.readFileSync('certs/server-key.pem'),
cert: fs.readFileSync('certs/server-crt.pem'),
ca: fs.readFileSync('certs/ca_client-crt.pem'),
//crl: fs.readFileSync('certs/ca-crl.pem'),
};
app.use(function (req, res, next) {
var log = new Date() + ' ' + req.connection.remoteAddress + ' ' + req.method + ' ' + req.url;
var cert = req.socket.getPeerCertificate();
if (cert.subject) {
log += ' ' + cert.subject.CN;
}
console.log(log);
next();
});
// Basic function to validate credentials for example
function check (name, pass) {
var valid = true
// Simple method to prevent short-circut and use timing-safe compare
valid = compare(name, 'john') && valid
valid = compare(pass, 'secret') && valid
return valid
}
if (useAuth) {
//cert authorization
app.use(function (req, res, next) {
var credentials = auth(req)
// Check credentials
// The "check" function will typically be against your user store
if (!credentials || !check(credentials.name, credentials.pass)) {
res.statusCode = 401
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
next();
} else {
next();
}
if (!req.client.authorized) {
return res.status(401).send('User is not authorized');
}
next();
});
options.requestCert = true;
options.rejectUnauthorized = false;
}
// app.use(function (req, res, next) {
// res.writeHead(200);
// res.end("hello Sikha");
// next();
// });
app.get('/', function (req, res) {
res.send('Node Soap Example!<br /><a href="https://github.com/macogala/node-soap-example#readme">Git README</a>');
})
var listener = https.createServer(options, app).listen(4433, function () {
var wsdl_path = "/wsdl";
soap.listen(app, wsdl_path, serviceObject, xml).on('error', (e) => {
console.log('Error happened: ', e.message)
});
console.log('Express HTTPS server listening on port ' + listener.address().port);
});