1 Star 2 Fork 0

eaglet / Chatroom

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.js 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
eaglet 提交于 2022-09-20 18:38 . 修复bug
//2020年2月
//e4glet
//app.js程序入口
const Koa=require('koa');
const app=new Koa();
//引入koa-ejs
const render = require('koa-ejs');
const views = require('koa-views');
//引入koa静态文件模块
const static = require('koa-static');
const path = require('path')
// 引入模块
const bodyParser = require('koa-bodyparser');
//引入koa-session
const Koa_Session=require("koa-session")
//引入层级路由模块
let router = require('./routes/index');
//引入socketserver模块
const socketserver=require('./server/socketserver');
//配置koa-session
const session_signed_key = ["secret"];
const session_config = {
key:'koa:sess',
maxAge:4000,
autoCommit:true,
overwrite:true,
httpOnly:true,
signed:true,
rolling:true,
renew:false,
};
//实例化
const session = Koa_Session(session_config,app);
app.keys = session_signed_key;
app.use(session);
// 配置静态web服务的中间件
app.use(static(
path.join( __dirname, './public')
));
// 挂载到app
// 使用参考:ctx.request.body 获取post提交的数据
//设置页面模版路径
app.use(views('views', { map: {html: 'ejs' }}));
//设置socket监听端口
socketserver(8082);
app.use(bodyParser());
//应用启动路由
app
.use(router.routes())
.use(router.allowedMethods());
//监听3000端口
app.listen(3000,()=>{
console.log("web服务器已启动,监听端口为3000");
console.log("web客户端访问地址:http://localhost:3000/");
console.log("websocket默认请求地址:http://localhost:8082");
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/e4glet/Chatroom.git
git@gitee.com:e4glet/Chatroom.git
e4glet
Chatroom
Chatroom
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891