-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (32 loc) · 1.15 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
// [START app]
import express from 'express';
import { createRequire } from 'module';
import Graph from 'quivero-api/data-structures/graph/Graph.js';
import { createVertices } from 'quivero-api/data-structures/graph/GraphVertex.js';
import { createEdges } from 'quivero-api/data-structures/graph/GraphEdge.js';
const require = createRequire(import.meta.url);
const app = express();
// [START enable_parser]
// This middleware is available in Express v4.16.0 onwards
app.use(express.json({ extended: true }));
// [END enable_parser]
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Listening on port: ${PORT}`);
});
app.get('/', (req, res) => {
// Driver program
// Create a sample graph
// A directed graph
const graph_ = new Graph(true);
// Nodes
const node_labels = ['A', 'B', 'C', 'D', 'E', 'F'];
const [A, B, C, D, E, F] = createVertices(node_labels);
// Vertices
const edge_vertices = [[A, B], [B, C], [C, D], [C, E], [E, B], [C, F], [F, B]];
// Add edges
graph_.addEdges(createEdges(edge_vertices));
res.send(graph_.describe());
});
// [END app]