随笔分类 -  Koa

将同一个应用程序同时作为 http 和 https
摘要:app.js const http = require('http') const https = require('https') const Koa = require('koa') const app = new Koa() app.use(ctx => { ctx.body = 'Hello 阅读全文

posted @ 2021-09-10 10:12 aisowe 阅读(87) 评论(0) 推荐(0) 编辑

怎样用原生 Koa 实现路由功能
摘要:index.js const Koa = require("koa"); const app = new Koa(); app.use((ctx) => { switch (ctx.url) { case "/": ctx.body = "<h1>index.html</h1>"; break; d 阅读全文

posted @ 2021-09-09 10:14 aisowe 阅读(30) 评论(0) 推荐(0) 编辑

怎样用 koa-router 实现 get 请求
摘要:index.js const Koa = require("koa"); const Router = require("koa-router"); const app = new Koa(); const router = new Router(); router.get("/", (ctx) = 阅读全文

posted @ 2021-09-09 10:13 aisowe 阅读(30) 评论(0) 推荐(0) 编辑

怎样用 koa-bodyparser 获取 POST 请求上下文中的表单数据
摘要:index.js const Koa = require("koa"); const bodyParser = require("koa-bodyparser"); const app = new Koa(); app.use(bodyParser()); app.use(async (ctx) = 阅读全文

posted @ 2021-09-09 10:12 aisowe 阅读(78) 评论(0) 推荐(0) 编辑

怎样用 koa 解析出 POST 请求上下文中的表单数据
摘要:index.js const Koa = require("koa"); const app = new Koa(); function bodyParser(ctx) { return new Promise((resolve, reject) => { let postData = ""; tr 阅读全文

posted @ 2021-09-09 10:11 aisowe 阅读(156) 评论(0) 推荐(0) 编辑

怎样用 Koa 写 Hello, World!
摘要:index.js const Koa = require("koa"); const app = new Koa(); app.use((ctx) => { ctx.body = "Hello, World!"; }); app.listen(3000); 阅读全文

posted @ 2021-09-09 10:11 aisowe 阅读(27) 评论(0) 推荐(0) 编辑

怎样用 Koa 搭配 fs 模块返回一个 html 文件给前端
摘要:index.js const fs = require("fs"); const Koa = require("koa"); const app = new Koa(); app.use(async (ctx) => { const html = fs.readFileSync("./index.h 阅读全文

posted @ 2021-09-09 10:11 aisowe 阅读(734) 评论(0) 推荐(0) 编辑

Koa 中怎样获取请求中的 query 参数
摘要:index.js const Koa = require("koa"); const app = new Koa(); app.use((ctx) => { const { request: { query: query1, querystring: queryString1 }, query, q 阅读全文

posted @ 2021-09-09 10:09 aisowe 阅读(426) 评论(0) 推荐(0) 编辑

怎样开发一个最简版 Koa 日志打印中间件
摘要:index.js const Koa = require("koa"); const app = new Koa(); /** * a simple log middleware * @param {object} ctx */ function logger() { return async fu 阅读全文

posted @ 2021-09-09 10:09 aisowe 阅读(92) 评论(0) 推荐(0) 编辑

怎样安装 Koa
摘要:npm i -S koa 阅读全文

posted @ 2021-09-09 10:08 aisowe 阅读(18) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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