-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (35 loc) · 1008 Bytes
/
server.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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cors = require('cors');
var path = require('path');
// Public directory
app.use(express.static(path.resolve('public')));
app.use(bodyParser.urlencoded({
extended: true,
}));
var corsOptions = {
origin: /^[^.\s]+\.mixmax\.com$/,
credentials: true
};
// Send the enhancement as a standalone page
app.get('/canvas', function(req, res) {
res.sendFile(path.resolve('enhancement/canvas.html'));
});
// Receive the enhancement
app.post('/api/canvas', cors(corsOptions), require('./api/canvasResolver'));
// Start the server
if (process.env.NODE_ENV === 'production')
app.listen(process.env.PORT || 8910);
else {
var pem = require('pem');
var https = require('https');
pem.createCertificate({days: 1, selfSigned: true}, function(err, keys) {
if (err)
throw err;
https.createServer({
key: keys.serviceKey,
cert: keys.certificate
}, app).listen(process.env.PORT || 8910);
});
}