代码拉取完成,页面将自动刷新
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cors = require('cors')
var multiparty = require('multiparty');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var private = require('./routes/private');
var orders = require('./routes/order');
var shopRouter = require('./routes/shop');
var private = require('./routes/private')
var findRouter = require('./routes/find')
var expressJWT = require("express-jwt")
var fxdRouter = require('./routes/fxdindex');
var zmyRouter = require('./routes/zmyindex')
var app = express();
app.use(cors())
app.use('/upload',express.static('upload'))
// //配置验证token的中间件
// app.use(expressJWT({
// //解析口令
// secret:"youzibo",
// //加密方式 SHA256 加密方式在express-jwt 里面叫做HS256
// algorithms:["HS256"]
// }).unless({
// //提供的是不需要验证token的接口,比如 注册接口 上传接口 登录接口
// path:['/login']
// }))
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(cors())
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use("/fxdupload",express.static("fxdupload"))
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/private', private);
app.use('/order', orders);
app.use('/shop', shopRouter);
app.use('/private', private)
app.use('/find', findRouter)
let WsList = [];
let WsIdList = [];
const { WebSocketServer } = require('ws');
const wss = new WebSocketServer({ port: 7000 });
wss.on("connection", function connection(ws, req) {
ws.send(JSON.stringify("连接成功"))
id = req.url.split("=")[1]
ws["id"] = id
if (WsIdList.indexOf(id) == -1) {
WsIdList.push(id)
WsList.push(ws)
console.log(WsIdList,'2222222222');
}
// 监听客户端发过来的消息
ws.on("message", function message(msg, isBinary) {
let data = JSON.parse(msg.toString())
let toId = data.to_id
let type = data.type
if (type == 'disconnect'){
ws.close()
WsIdList = []
WsList =[]
}else{
let content = JSON.stringify(data.content)
WsList.forEach(item => {
if (item.id == toId) {
if (type == 'receive') {
item.send(content)
console.log(content,'555555555555');
}
}
})
}
})
})
app.use('/fxd', fxdRouter)
app.use('/zmy',zmyRouter)
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。