-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (36 loc) · 1.12 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
44
45
46
var nconf = require("nconf");
var bodyParser = require('body-parser')
var dataUriToBuffer = require('data-uri-to-buffer')
var express = require('express')
var app = express()
nconf.argv().env().file({ file: 'local.json'});
/**
* This is your custom transform function
* move it wherever, call it whatever
*/
var transform = require("./transformer")
// Set up some Express settings
app.use(bodyParser.json({ limit: '1mb' }))
app.use(express.static(__dirname + '/public'))
/**
* Home route serves index.html file, and
* responds with 200 by default for revisit
*/
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html')
})
/**
* Service route is where the magic happens.
*/
app.post('/service', function(req, res) {
var imgBuff = dataUriToBuffer(req.body.content.data)
// Transform the image
var transformed = transform(imgBuff)
var dataUri = 'data:' + imgBuff.type + ';base64,' + transformed.toString('base64')
req.body.content.data = dataUri
req.body.content.type = imgBuff.type
res.json(req.body)
})
var port = nconf.get("port");
app.listen(port)
console.log('server running on port: ', port)