-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (51 loc) · 1.67 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
47
48
49
50
51
52
53
54
55
56
57
'use strict';
require('dotenv').config();
const { join } = require('path');
const express = require('express');
const app = express();
const router = express.Router();
const fs = require('fs');
const cheerio = require('cheerio');
const {
getDiscoveryInfo,
getFile,
checkFileInfo,
putFile,
getRawBody,
checkAccess,
getFileNames,
handleHeaders,
createEmptyFile,
copyFile,
} = require('./middleware');
const port = process.env.PORT || 4000;
// const key = readFileSync('./certificates/wopi-key.pem')
// const cert = readFileSync('./certificates/wopi-cert.pem')
// const pfx = readFileSync(join(__dirname, 'certificates', 'dev-cert.pfx'))
// const passphrase = 'p@ssw0rd'
// const secureProtocol = 'TLSv1_2_method'
app.use(getRawBody); // adds the raw binary of the post body to req.rawBody
// app.get('*', getDiscoveryInfo)
router.route('/files/:file_id/contents').get(getFile).post(putFile);
router.route('/files/:file_id').get(checkFileInfo).post(handleHeaders);
app.use('/wopi', checkAccess);
app.use('/wopi', router);
app.post('/create/:file_id', createEmptyFile);
app.post('/add-file', copyFile);
app.get('/fileNames', getFileNames);
app.get('/discovery', getDiscoveryInfo);
app.get('/', (req, res, next) => {
// res.sendFile(join(__dirname, 'SampleHostPage.html'))
res.sendFile(join(__dirname, 'index.html'));
});
app.get('/index', (req, res) => {
var htmlContent = fs.readFileSync("hostPage.html");
const $ = cheerio.load(htmlContent);
res.send($.html());
})
// createServer({ pfx, passphrase, secureProtocol }, app).listen(port, () => {
// console.log(`server running on port ${port}`)
// })
app.listen(port, () => {
console.log(`server running on port ${port}`);
});