-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (33 loc) · 900 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
34
35
36
37
const Koa = require('koa');
const serve = require('koa-static');
const cors = require('@koa/cors');
const fs = require('fs')
const config = require('./www/config.json')
const connect = require('./utils/Message')
const WebSocket=require('ws')
if(!fs.existsSync('./www/tiles')){
fs.mkdirSync('./www/tiles')
fs.writeFileSync('./www/list.json',JSON.stringify({}))
}
const app = new Koa()
app.use(cors());
const router=require('./controller/index.js')
app.use(router.routes()).use(router.allowedMethods());
app.use(serve('www'));
const wss=new WebSocket.Server({
port:config.ws.port
},()=>{
console.log('ws inited');
})
wss.on('headers',(req)=>{
console.log(req);
})
wss.on('connection',ws=>{
connect.receieve(msg=>{
ws.send(JSON.stringify(msg))
})
})
const server=app.listen(config.port,()=>{
console.log(`server start at http://localhost:${config.port}`);
})
server.setTimeout(0)