forked from hmrc/hmrc-screens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (40 loc) · 1.3 KB
/
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
45
46
var bodyParser = require('body-parser')
var express = require('express')
var path = require('path')
var app = express()
var saveImages = require('./lib/save-images')
var saveNote = require('./lib/save-note')
app.set('port', 3000)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use('/assets', express.static(path.join(__dirname, 'assets')))
app.use('/node_modules', express.static(path.join(__dirname, 'node_modules')))
app.use('/service', express.static(path.join(__dirname, 'service')))
app.get(['/', '/index.html'], function (req, res) {
res.sendFile(path.join(__dirname, '/index.html'))
})
app.post('/save-note', function (req, res) {
if (Object.keys(req.body).length !== 0) {
var servicesDir = path.join(__dirname, 'service')
saveNote(req.body, servicesDir).then(function (data) {
res.json(data)
})
} else {
res.json({})
}
})
app.post('/save-images', function (req, res) {
if (Object.keys(req.body).length !== 0) {
var servicesDir = path.join(__dirname, 'service')
saveImages(req.body, servicesDir).then(function (data) {
res.json(data)
})
} else {
res.json({})
}
})
var server = app.listen(app.get('port'), function () {
var port = server.address().port
console.log(`Listening on port ${port}`)
})
module.exports = server