chenshenhai / koa2-note Goto Github PK
View Code? Open in Web Editor NEW《Koa2进阶学习笔记》已完结🎄🎄🎄
Home Page: https://chenshenhai.github.io/koa2-note
License: MIT License
《Koa2进阶学习笔记》已完结🎄🎄🎄
Home Page: https://chenshenhai.github.io/koa2-note
License: MIT License
function mkdirsSync( dirname ) {
if (fs.existsSync( dirname )) {
return true
} else {
if (mkdirsSync( path.dirname(dirname)) ) {
fs.mkdirSync( dirname )
return true
}
}
}
session缺少一个定时清理功能
�我感觉是没有把文件流清空,请问这个怎么解决
koa2-note/demo/static-server/util/dir.js
Line 21 in fab3aa6
正在学习此教程,感觉很不错,想问下webpack2有计划升级到webpack4么?
`
Request Headers:
Accept: /
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Connection: keep-alive
Content-Length: 1243
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary0nc6DwwRlVIQdGiJ
Cookie: captcha_token=408f7903a848baed9d5878f16cb73844;
USER_SID=lCyHKbOwfu6Kle9RdT37AUW3mAHzp-BR
Host: localhost:8000
Origin: http://localhost:8000
Referer: http://localhost:8000/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/67.0.3396.99 Safari/537.36
X-Requested-With: XMLHttpRequest
Request payload
------WebKitFormBoundary0nc6DwwRlVIQdGiJ
Content-Disposition: form-data; name="file"; filename="[email protected]"
Content-Type: image/png
------WebKitFormBoundary0nc6DwwRlVIQdGiJ--
`
文件上传前端上传的数据是这样的
服务端用的koa2,上传方法是你的uploadFile方法,但是在调用的时候
// 解析请求文件事件
busboy.on('file', )这个方法并不会触发,我暂时还不知道如何解决,能否给予帮助,谢谢
异步上传图片的实现,选择图片后,现象: 上传进度0%,图片没有上传成功
function getSqlMap () {
let basePath = __dirname
basePath = basePath.replace(/\\/g, '\/')
let pathArr = basePath.split('\/')
pathArr = pathArr.splice( 0, pathArr.length - 1 )
basePath = pathArr.join('/') + '/sql/'
let fileList = walkFile( basePath, 'sql' )
return fileList
}
没看懂,难道不是path.join就能直接解决
Use 'utf8' instead of 'binary' to avoid garbled characters when inserting Chinese character into database here.
没有热更新,每次都要反复的关闭,启动。
是一个学习node及koa的好地方,再次感谢分享
koajs-design-note 和 koa2-note 的内容好像变成一样的了。我记得之前看koa2-note 的内容不是这样的。
https://github.com/ChenShenhai/koa2-note/blob/master/note/mysql/async.md
下面的代码中,如果创建连接失败,应该是 reject( err )
吧?
pool.getConnection(function(err, connection) {
if (err) {
// 这里我觉得应该是 reject( err ),而不是 resolve。
resolve( err )
} else {
// ...
在 /demo/static-server/util/file.js
里面有这样的一段代码 :
let content = fs.readFileSync(filePath, 'binary' )
其实,这里需要对文件类型进行判断的,因为中文使用 binary
读取出来会是乱码的。个人觉得只有是图片、视频等才有必要使用 binary
读取。其他的用 utf8
便可。
function mkdirsSync( dirname ) {
if (fs.existsSync( dirname )) {
return true
} else {
if (mkdirsSync( path.dirname(dirname)) ) {
fs.mkdirSync( dirname )
return true
}
}
}
It would return hello world
all the time.
使用session存入mysql数据库时程序没有报错,也能生成sessionid,但是mysql数据库就是没有值。这是什么原因导致的呢。
then throw an error
这个笔记非常受用, 对我来说是一个教程,里面有 react 服务端渲染的部分,
希望能出一份 vue 服务端渲染的小demo
// 上传文件事件
result = await uploadFile( ctx, {
fileType: 'album',
path: serverFilePath
})
console.log(result)
async function a() {
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve(1)
},1000)
})
}
let b = await a()
console.log(b)
如上面的代码,图片上传完后可以拿到result,但是执行下面的内容却跑不下去,请问是什么原因
Add the middleware like this, use maxAge to set the time, but don't work.
The cookie didn't be invalid.
Why?
app.use(session({
maxAge:5000
}))
koa2-note/demo/upload/util/upload.js
Line 90 in fab3aa6
这行怎么理解 ,有什么作用
过来学习koa,结果被logo吸引了,之前也看过很多lowpoly风格的图,感觉你这个做的特别好,所以想求一下制作方法或者链接,谢谢~
我已经安装好了mysql(MAC)并配置了全局变量,使用idea内置的mysql连接工具测试连接成功。
使用命令行工具测试连接成功
let store = new MysqlSession({
user: 'root',
password: '12345678',
database: 'test',
host: '127.0.0.1',
port: 3306,
insecureAuth: true
})
(node:2837) UnhandledPromiseRejectionWarning: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Handshake.ErrorPacket (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/protocol/sequences/Handshake.js:130:18)
at Protocol._parsePacket (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/Users/stevenlee/github/test/koa2-note/demo/mysql/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
--------------------
在session
、mysql
两个模块下连接mysql都遇到了这个问题,使用的node包分别为koa-mysql-session
与mysql
.
注:我只修改了数据库连接的配置信息。
上网查了好久都没解决,如果哪位大神有什么好的思路,跪求分享,不胜感激:ambulance:
在webstorm中,ansyc/await的函数在断点调试会跳过,有解决方案么?
教程循序渐进,非常有帮助,夸张点说1天就入门(零基础除外),你在留下学习痕迹的同时,让我们结合官方文档学习的时候,更快捷的上手koa2,一堆话化作一句感激吧~~~!
顺祝: @chenshenhai 及大家春节愉快。
环境:
koa2.3.0;
node7.10.0;
busboy:0.2.14;
问题:
我按照“文件上传”里的"上传文件简单实现"方式想实现koa2下处理文件上传。
busboy监听的file,field,error都没有跑进去,只能跑到finish里。代码都是按照文档例子敲的。这是怎么会回事啊
可以尝试gitbook
阅读性会提升很多
问下作者文档怎么生成的,我需要去看些什么资料
我在 mime中加了ttf 和 woff 的mime。
'ttf': 'application/octet-stream', 'woff': 'font/x-woff', 'woff2': 'application/font-woff2',
但是在浏览器中一直抱异常。
grids.html:1 Failed to decode downloaded font: http://127.0.0.1:3300/fonts/fontawesome-webfont.woff grids.html:1 OTS parsing error: incorrect file size in WOFF header grids.html:1 Failed to decode downloaded font: http://127.0.0.1:3300/fonts/fontawesome-webfont.ttf grids.html:1 OTS parsing error: incorrect entrySelector for table directory
请问这个怎么解决?
看了下官方的实例,此处是connection.end().
下面连接池部分是用的connection.release().
不知道是不是只有我有这个问题.
: )
我把demo/project里面的代码放在服务上面跑,配置完成后,执行
npm run start_server
出现如下错误
module.js:472
throw err;
^
Error: Cannot find module './../models/user-info'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at require (internal/module.js:20:19)
at Object.<anonymous> (/data/koa2-note/demo/project/server/services/user-info.js:6:19)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at require (internal/module.js:20:19)
at Object.<anonymous> (/data/koa2-note/demo/project/server/controllers/user-info.js:1:87)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
大神,按照你的demo,在package中有如下代码
"dev": "npm run dev_server & npm run dev_static",
"dev_server": "nodemon --harmony ./server/app",
"dev_static": "webpack --watch --config ./static/build/webpack.dev.config.js",
但是我执行npm run dev 总是能启动项目,但是不能启动webpack watch,如果交换了dev_server和dev_static的位置,又只能启动webpack watch不能启动项目!求大神指导
请问 koa session 这一块怎么跑起来的,我怎么跑不起来? 是不是因为里面操作数据库 MySQL 没跑起来,怎么跑MySQL;
你好,如果不封装sql成同步会有什么问题吗?
// 子路由2
let page = new Router()
page.get('/404', async ( ctx )=>{
ctx.body = '404 page!'
}).get('/helloworld', async ( ctx )=>{
ctx.body = 'helloworld page!'
})
该部分代码走不进去
koa2-note/demo/project/server/models/user-info.js
你好,后期会不会有 restful api 的架构,包括一些验证 ,如 koa-jwt 等 。静静等待
异步上传图片的fileType设置为album或者common是什么鬼 @chenshenhai
npm 安装webpack-2.2.0-rc3不上,安装了4.18.0, npm run dev ,没有问题,但是看不到页面,如何升级?
请问一下:
1,这个教程是否还在为最新版本的koa做同步更新呢?
2,ejs模版引擎的教程是否可以加入layout布局的讲解?
3,数据库操作时是否可以加入Sequelize的ORM的相关教程?
4,如何设置自己的域名,而非采用localhost的方式运行呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.