-
Notifications
You must be signed in to change notification settings - Fork 46
/
app.js
93 lines (77 loc) · 2.44 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// const https = require('https');
const https = require('http');
const fs = require('fs');
const express = require('express')
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const app = express();
const queryString = require('querystring');
const URL = require('url');
const socket = require('./service/socket');
const router = require('./routes/router').router;
//获取认证证书
// var key = fs.readFileSync('./key/2_www.liudongtushuguan.cn.key');
// var cert = fs.readFileSync('./key/1_www.liudongtushuguan.cn_bundle.crt');
// var options = {
// key : key,
// cert : cert,
// };
//配置小程序二维码生成文件
app.use('/index', express.static('index'));
app.use(cookieParser());
app.use(bodyParser.json());
// const httpsServer = https.createServer(options,app);
const httpsServer = https.createServer(app);
httpsServer.listen(8080,() =>{
console.log('listening 443 port');
});
socket(httpsServer);
app.use(router);
// app.get('/', (req , res) =>{
// console.log('someone requested!');
// res.cookie('mycookie','value',{time : new Date()});
// res.status(200).send('Welcome to liudongtushuguan!');
// });
// app.get('/cookie',(req , res) => {
// console.log(req.cookies);
// //var mycookie = req.cookies.mycookie;
// res.end('mycookie');
// });
// const wss = new WebSocket.Server({server : httpsServer});
// wss.on('connection',(ws, req) => {
// let sessionId = queryString.parse(URL.parse(req.url).query).sessionId;
// ws.id = sessionId;
// console.log('someone connect');
// console.log(wss.clients);
// wss.clients.forEach((client) => {
// console.log(Object.keys(client));
// });
// ws.on('message' , (msg) => {
// let msgObj = JSON.parse(msg);
// if(sessions[msgObj.targetId]){
// wss.clients.forEach((client) => {
// if(client.id === msgObj.targetId){
// let data = {
// time : msgObj.time,
// borrower :msgObj.nickName,
// book :msgObj.bookName,
// borrowerId : sessions[sessionId],
// bookId : msgObj.bookId,
// wxNum : msgObj.wxNum,
// phoneNum : msgObj.phoneNum,
// msg : msgObj.msg
// };
// client.send(JSON.stringify(data));
// }
// });
// }
// console.log(msg);
// //ws.send('you send '+msg);
// });
// //ws.send('hello');
// });
// app.get('/login',(req,res) => {
// res.status(200);
// console.log(req.query);
// res.json({"code" : req.query});
// });