diff --git a/demos/server.js b/demos/server.js index 9dd8c05..0daa974 100644 --- a/demos/server.js +++ b/demos/server.js @@ -2,6 +2,8 @@ let express = require('express'); let app = express(); let path = require('path'); let bodyParser = require('body-parser'); +let FormData = require('form-data'); +const Readable = require('stream').Readable; let constellation = require('../lib/constellation'); app.use(bodyParser.json()); @@ -50,3 +52,30 @@ app.post('/postSpecs', function(req,res) { res.status(405).send(String(error)); } }); + +app.post('/sendToKnox', function(req,res) { + + let form = new FormData(); + let sbolDocs = JSON.parse(req.body['sbolDocs[]']); + + for(let sbol of sbolDocs){ + let stream = new Readable(); + stream.push(sbol); + stream.push(null); + form.append('inputSBOLFiles[]', stream, { + filename : 'test.xml', + contentType: 'application/xml', + knownLength: sbol.length + }); //extra fields necessary + } + form.append('outputSpaceID', req.body.designName); + + form.submit('http://localhost:8080/sbol/importCombinatorial', function(error, result) { + if (error) { + console.log('Error!'); + res.status(405).send(String(error)); + } else{ + res.status(200).send(String(result)); + } + }); +}); diff --git a/demos/static/client.html b/demos/static/client.html index 873ca90..63ae7e9 100644 --- a/demos/static/client.html +++ b/demos/static/client.html @@ -7,7 +7,8 @@ - + + @@ -46,7 +47,7 @@