-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
29 lines (26 loc) · 1 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
const http=require('http')
const express = require('express')
const WebSocket=require('ws')
const app = express()
app.use(express.json());
const server = http.createServer(app);
const wss=new WebSocket.Server({server});
const compression = require('compression')
const serveIndex = require('serve-index');
const url = require('url');
app.use(compression({filter:shouldCompress}))
function shouldCompress (req, res) {
if (req.headers['x-no-compression']) return false
return compression.filter(req, res)
}
app.use(express.static('output'))
require('./server/server.js')(app,wss).then(()=>{
app.use('/code',(req,res,next)=>{
filename=url.parse(req.url).pathname.split('/').pop()
if(['data.db','vapidKeys.json'].includes(filename)) res.send('No access to that file! This file contains secrets used for sending notifications, or contains the server data.')
else next()
})
app.use('/code',express.static(__dirname,{index:false}))
app.use('/code', serveIndex(__dirname));
})
server.listen(process.env.PORT||8000)