-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (33 loc) · 1.32 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
const express = require('express');
const path = require('path');
const app = express();
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, './build')));
const bodyParser = require('body-parser');
// parse application/json
app.use(bodyParser.json());
app.get("/ldapAuth", (req, res) => {
const ldap = require('ldapjs');
const ldap_url = req.query.ldap_url;
const user = req.query.user;
const password = req.query.password;
console.log("Ldap url : "+ldap_url);
console.log("Ldap user : "+user);
console.log("Ldap password : "+password);
const client = ldap.createClient({
url: ldap_url
});
client.bind(user, password, function (err) {
if (err) {
console.error("Failed to connect to LDAP with url : " + ldap_url + " and user : " + user);
res.status(500);
res.json("LDAP connection with url : " + ldap_url + " and user : " + user + " failed " + err);
} else {
console.log("Connect to LDAP with url : " + ldap_url + " and user : " + user + " - SUCCESS");
res.status(200).send("LDAP connection with url : " + ldap_url + " and user : " + user + " success ");
}
})
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log('App is listening on port ' + port);