-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (31 loc) · 1006 Bytes
/
index.js
File metadata and controls
37 lines (31 loc) · 1006 Bytes
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
const proxy = require("express-http-proxy");
const app = require("express")();
const session = require("express-session");
const Keycloak = require("keycloak-connect");
var memoryStore = new session.MemoryStore();
app.use(
session({
secret: "notSoSecret",
resave: false,
saveUninitialized: true,
store: memoryStore,
})
);
var keycloak = new Keycloak({
store: memoryStore,
});
app.use(keycloak.middleware());
app.get("/api/*", keycloak.protect(), proxy("http://localhost:3001/", {
proxyReqPathResolver: function (req) {
var parts = req.url.split('?');
var queryString = parts[1];
var updatedPath = parts[0].replace(/api/, '/');
return updatedPath + (queryString ? '?' + queryString : '');
}
}));
app.get("/*", keycloak.protect(), proxy("http://localhost:3000/"));
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
console.log("Authproxy listening at http://%s:%s", host, port);
});