Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add server example (using express)

  • Loading branch information...
commit e847bd5cfbdaa0166d1340fef64f0f787e05b00d 1 parent eab415b
Gregoire Lejeune authored
25 tests/server/app.js
... ... @@ -0,0 +1,25 @@
  1 +var app = require('express').createServer();
  2 +
  3 +var sys = require('sys'),
  4 + graphviz = require('graphviz');
  5 +
  6 +app.set('views', __dirname + '/views');
  7 +
  8 +app.get('/', function(req, res){
  9 + res.render('index.ejs', {});
  10 +});
  11 +
  12 +app.get('/image.png', function(req,res){
  13 + var g = graphviz.digraph("G");
  14 + var n1 = g.addNode( "Hello" );
  15 + n1.set( "color", "red" );
  16 + n1.set( "style", "filled" );
  17 + g.addNode( "World" );
  18 + var e = g.addEdge( n1, "World" );
  19 + e.set( "color", "red" );
  20 + g.render( "png", function(render) {
  21 + res.send(render, { 'Content-Type': 'image/png' })
  22 + } );
  23 +})
  24 +
  25 +app.listen(3000);
3  tests/server/views/index.ejs
... ... @@ -0,0 +1,3 @@
  1 +<p>Hello !</p>
  2 +
  3 +<img src="/image.png" />
5 tests/server/views/layout.ejs
... ... @@ -0,0 +1,5 @@
  1 +<html>
  2 + <body>
  3 + <%- body %>
  4 + </body>
  5 +</html>

0 comments on commit e847bd5

Please sign in to comment.
Something went wrong with that request. Please try again.