5 Star 0 Fork 0

陈亚丁/pinterest后端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
陈亚丁 提交于 2023-05-29 15:00 . 聊天修改
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;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Cyading/pinterest-backend.git
git@gitee.com:Cyading/pinterest-backend.git
Cyading
pinterest-backend
pinterest后端
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385