-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 1022 Bytes
/
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
const express = require('express')
const app = express()
var os = require('os');
const http = require('http')
const server = http.createServer(app)
const path = require('path')
const fs = require('fs')
const {forceDomain} = require('forcedomain')
const PORT = process.env.PORT || 5000;
app.use(forceDomain({
hostname: 'coly-ar-app.herokuapp.com',
protocol: 'https'
}));
app.use(express.static(__dirname + '/client/public'))
app.use(express.json({limit:'50mb'}))
app.use(express.urlencoded({limit:'50mb', extended:true}))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/client/index.html'))
})
app.post('/image', (req, res) => {
const imgPath = './imageUploads/' + Date.now() + '.png';
let image = req.body.image;
const base64Data = image.replace(/^data:([A-Za-z-+/]+);base64,/, '');
fs.writeFileSync(imgPath, base64Data, {encoding: 'base64'});
console.log("image received and saved")
})
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})