ruanyf / koa-demos Goto Github PK
View Code? Open in Web Editor NEWA collection of simple demos of Koa
A collection of simple demos of Koa
文档最后一段:
Usefule Links
拼写有误,应该为 Useful Links
现在首先判断xml,返回xml,
习惯默认返回html
所以建议把html放在第一个判断
curl是linux的命令,这里假如我模拟一个Post请求,请求本地的3000端口,,请求为files: 本地的文件的真是路径(例如C:\Users\xx\Desktop\koa-demos-master.zip),
const files = ctx.request.body.files || {} 就是直接拿到了 C:\Users\xx\Desktop\koa-demos-master.zip这个路径了,然后下面又是遍历,,结果下面 又对这个files遍历了
const
filePath = path.join(tmpdir,file.name)
file.name肯定会是undefined,然后文件肯定是不能上传,我想问的就是在windows上这个例子该怎么写啊?如何更好然后模拟测试呢?不知道怎么写?
代码
const Koa = require('koa');
const fs = require('fs.promised');
const app = new Koa();
const main = async function (ctx, next){
ctx.response.type = 'html';
ctx.response.body = await fs.readFile('./demos/template.html', 'utf8');
}
app.use(main);
app.listen(3000);
报错
Error: Cannot find module 'fs.promised'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (f:\github\myStudy\koa\demos\10.js:2:12)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
127.0.0.1:3000
实例代码
const main = cxt =>{
cxt.throw(500);
}
改为
const main = cxt =>{
cxt.response.status = 500;
}
下面代码运行不到
app.on('error', (err, cxt) =>{
console.error('server error', err);
});
运行环境:ARM VPS + ubuntu
运行 $ docker image build -t koa-demo . 之后,提出如下错误:
[Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
是否可以看下怎么解决,谢谢。
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.