Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
markuskonk committed Feb 20, 2018
1 parent cbe2c90 commit fc1790a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Use Node v4 as the base image.
FROM node:4
FROM node:8.9.4

ADD . /app

RUN cd /app; \
npm install --production

# Run node
CMD ["node", "/app/index.js"]
8 changes: 4 additions & 4 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
*/

const debug = require('debug')('bindings:config')
const debug = require('debug')('bindings:config');

var env = process.env;
var c = {};
c.net={}
c.net.port = env.BINDINGS_PORT || 8092
c.net={};
c.net.port = env.BINDINGS_PORT || 8092;

module.exports = c;
module.exports = c;
26 changes: 7 additions & 19 deletions controllers/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

const express = require('express');
const bodyParser = require('body-parser');
const debug = require('debug')('bindings:bindings');
const debug = require('debug')('bindings');
const fs = require('fs');

let bindings = {};
Expand All @@ -32,8 +32,9 @@ bindings.start = (conf) => {
app.post('/api/v1/bindings', function(req, res) {
switch (req.body.purpose) {
case 'showFigureCode':
bindings.showFigureCode(req.body);
res.send({callback: 'ok'});
saveRmarkdown(readRmarkdown(req.body.id, req.body.mainfile));
res.send({
callback: 'ok'});
break;
default:
break;
Expand All @@ -46,7 +47,7 @@ bindings.start = (conf) => {
});
};

bindings.readRmarkdown = function( compendiumId, mainfile ) {
let readRmarkdown = function( compendiumId, mainfile ) {
if ( !compendiumId | !mainfile ) {
throw new Error('File does not exist.');
}
Expand All @@ -56,23 +57,10 @@ bindings.readRmarkdown = function( compendiumId, mainfile ) {
throw new Error('File does not exist.');
}
});
const readerStream = fs.createReadStream(paper);
readerStream.setEncoding('utf8');
let data = '';
readerStream
.on('data', function(chunk) {
data += chunk;
})
.on('end', function() {
bindings.saveRmarkdown(data);
return data;
})
.on('error', function(err) {
debug(err);
});
return fs.readFileSync(paper, 'utf8');
};

bindings.saveRmarkdown = function(data) {
let saveRmarkdown = function(data) {
fs.writeFile(__dirname + '/testdata/paper_interactive.Rmd',
data, 'utf8', function(err) {
debug(err);
Expand Down

0 comments on commit fc1790a

Please sign in to comment.