-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.07 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
require('dotenv').config()
const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const cors = require('cors')
const generateContract = require('./contract/generateContract')
const contractData = require('./contractData')
app.use(express.static(__dirname + '/public'))
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.get('/', async (req, res) => {
res.send('OK')
})
app.post('/docx', async (req, res) => {
try {
let filePath = `docs/contract-${+new Date()}.docx`
const contractData = { ...req.body }
let filename = await generateContract(contractData)
res.download(path.join(__dirname, filename), function (err) {
// console.log(err)
})
} catch (err) {
console.log(err)
}
})
app.post('/cb', async (req, res) => {
console.log('************\n')
console.log(req.body)
console.log('\n************')
res.send('ok')
})
const PORT = process.env.PORT || 5000
app.listen(PORT, () => {
console.log(`LISTENING TO PORT ${PORT}`)
})