-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (60 loc) · 1.31 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
require('dotenv').config();
const app = require("express")();
const http = require("http").Server(app);
import OrientDB from 'orientjs';
const client = OrientDB({
host: process.env.ORIENTDB_HOST,
port: process.env.ORIENTDB_PORT,
username: process.env.ORIENTDB_USERNAME,
password: process.env.ORIENTDB_PASSWORD
});
const port = process.env.SERVER_PORT || 3000;
const boostrap = pool => {
app.use((req, res, next) => {
pool
.acquire()
.then(session => {
res.locals.db = session;
res.on("finish", () => {
session.close();
});
next();
})
.catch(err => {
res.status(500).send(err);
});
});
app.get("/", function(req, res) {
res.sendFile(__dirname + "views/index.html");
});
app.get("/graph", function(req, res) {
res.locals.db
.query("select from Actors limit 20")
.all()
.then(actors => {
res.send(actors);
})
.catch(err => {
res.status(500).send(err);
});
});
http.listen(port, function() {
console.log("listening on *:" + port);
});
};
client
.connect()
.then(() => {
return client.sessions({
name: "graph",
pool: {
max: 25
}
});
})
.then(pool => {
boostrap(pool);
})
.catch(err => {
console.log(err);
});