-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathweb.js
More file actions
26 lines (23 loc) · 1 KB
/
Copy pathweb.js
File metadata and controls
26 lines (23 loc) · 1 KB
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
// usage: http://localhost:3000/?query=match%20path=(n)-->(m)%20return%20path%20limit%20100
const express = require('express');
const ng = require("./neo4j-graphviz");
const app = express();
const url=process.env.NEO4J_URL || "neo4j://localhost";
const user=process.env.NEO4J_USER || "neo4j";
const pass=process.env.NEO4J_PASSWORD || "test";
const db=process.env.NEO4J_DATABASE || "neo4j";
app.get('/', function(req, res){
const type = req.accepts("image/jpeg")||req.accepts("image/jpg") ? "jpeg" :
req.accepts("image/svg") || req.accepts("image/svg+xml") ? "svg" : "png";
const style= "neato";
const query = req.params["query"] || `MATCH (n)-[r]->(m) RETURN * LIMIT 20`;
ng.renderGraph(url,user, pass, db, query, style, type, function(error,data) {
if (error) res.status(500).send(error);
else {
res.type("image/"+type).send(data);
}
});
});
const port = process.env.PORT || 3001;
console.log(`Server started on ${port} against ${url} user ${user} db ${db}`);
app.listen(port);