随笔分类 -  node

摘要:koa-views const koa = require("koa");const views = require("koa-views");const path = require("path");let app = new koa();app.use(views(path.join(__dir 阅读全文
posted @ 2021-04-08 14:16 莣ㄋ噯 阅读(262) 评论(0) 推荐(0) 编辑
摘要:const mysql = require("mysql");const co = require("co-mysql");let conn = mysql.createPool({ host: "localhost", user: "root", password: "root", databas 阅读全文
posted @ 2021-04-02 11:01 莣ㄋ噯 阅读(72) 评论(0) 推荐(0) 编辑
摘要:/* 设置签名的 Cookie 密钥。 */app.keys = ["123", "456", "789", "111"];app.use(async ctx => { ctx.cookies.set("name", "age", { /* 设置cookies有效期 */ maxAge: 9 * 2 阅读全文
posted @ 2021-04-02 09:57 莣ㄋ噯 阅读(202) 评论(0) 推荐(0) 编辑
摘要:第一种方法通过设置头部处理跨域 app.use(async (ctx, next) => { ctx.set("Access-Control-Allow-Origin", "http://192.168.31.45:63341"); /* 处理跨域携带cookie时出现的问题 */ ctx.set( 阅读全文
posted @ 2021-04-02 09:43 莣ㄋ噯 阅读(536) 评论(0) 推荐(0) 编辑
摘要:const serve = require("koa-static");const Router = require("koa-router"); app.use(serve("../static", { /* 文件的超时时间 */ maxage: 7 * 24 * 60 * 60 * 1000, 阅读全文
posted @ 2021-04-02 09:09 莣ㄋ噯 阅读(215) 评论(0) 推荐(0) 编辑
摘要:/* 可以添加的全局属性 */// app.context.a=12; /* get请求的数据 */// ctx.query/* 客户端的ip */// ctx.ip/* 请求头 */// ctx.headers/* 设置请求头 */// ctx.set('content-type', json`) 阅读全文
posted @ 2021-04-01 16:54 莣ㄋ噯 阅读(1578) 评论(0) 推荐(0) 编辑
摘要:入口app.js const koa = require("koa");const app = new koa();const Router = require('koa-router');const router = new Router();/* 引用路由user */const user = 阅读全文
posted @ 2021-04-01 15:38 莣ㄋ噯 阅读(191) 评论(0) 推荐(0) 编辑
摘要:const express = require("express");const port = 8080;const app = express();/* 解析post */const body = require("body-parser");/* 解析cookie */const cookieP 阅读全文
posted @ 2021-03-31 17:10 莣ㄋ噯 阅读(65) 评论(0) 推荐(0) 编辑
摘要://服务端 let io = require('socket.io')();let userList = [ { name: "用户1", age: "18", id: "00000001" }, { name: "用户2", age: "18", id: "00000002" }, { name: 阅读全文
posted @ 2021-03-27 17:30 莣ㄋ噯 阅读(128) 评论(0) 推荐(0) 编辑
摘要://服务端let io = require('socket.io')();io.sockets.on('connection', socket => { //初始化之后通过join加入room1房间 socket.join("room1", function () { console.log("Jo 阅读全文
posted @ 2021-03-27 16:48 莣ㄋ噯 阅读(293) 评论(0) 推荐(0) 编辑
摘要:const io = require('socket.io')({cors:true});//{cors:true}处理跨域io.on('connection', client => { client.on('event', data => { console.log(data); }); setT 阅读全文
posted @ 2021-03-27 14:59 莣ㄋ噯 阅读(541) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示