diff --git a/package.json b/package.json index e100780..d1a20bd 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,6 @@ "express": "^4.13.3", "node-uuid": "^1.4.7", "fs-extra" : "^1.0", - "connect-busboy" : "^0.0.2" + "busboy" : "^0.2.13" } } diff --git a/server.js b/server.js index aa060dd..cee695d 100644 --- a/server.js +++ b/server.js @@ -3,29 +3,26 @@ const path = require('path'); //used for file path const fs = require('fs-extra'); //File System - for file manipulation var uuid = require('node-uuid'); var exec = require('child_process').exec; - -const PORT = 8080; - -var deleteFolderRecursive = function(path) { - if( fs.existsSync(path) ) { - fs.readdirSync(path).forEach(function(file,index){ - var curPath = path + "/" + file; - if(fs.lstatSync(curPath).isDirectory()) { // recurse - deleteFolderRecursive(curPath); - } else { // delete file - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(path); - } -}; +var Busboy = require('busboy'); +const PORT = process.env.port || 9021; var app = express(); app.get('/', function (req, res) { - res.send('

Instructions

In order to watermark a pdf send two PDF files to /upload, one with fieldname watermark and one with fieldname pdf-to-watermark. The watermark pdf will get stamped on each page of the pdf-to-watermark pdf and the resulting PDF streamed back.

curl -i -F "watermark=@watermark.pdf" -F "pdf-to-watermark=@my.pdf" http://localhost:'+PORT+'/watermark > watermarked.pdf
\n'); + let home = __dirname+"/home.html"; + let stat = fs.statSync(home); + var readStream = fs.createReadStream(home); + var html = ""; + readStream.on('data', function (chunk) { + html += chunk.toString().replace("@PORT", PORT); + }); + readStream.on('end', function(){ + res.status(200).send(html); + }); + }); -var Busboy = require('busboy'); + + /* ========================================================== Create a Route (/watermark) to handle the upload (handle POST requests to /upload)