• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript koa-body类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中koa-body的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-body类的具体用法?TypeScript koa-body怎么用?TypeScript koa-body使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了koa-body类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

    md.remove(ctx.request.body.id);
    ctx.body = true;
});
router.post('/edit', (ctx, next) => {
    ctx.body = md.getFile(ctx.request.body.id);
});
router.post('/updateCont', (ctx, next) => {
    md.setFile(ctx.request.body.id, ctx.request.body.cont);
    ctx.body = true;
})
router.post('/updateTitle', (ctx, next) => {
    const
        id = ctx.request.body.id,
        title = ctx.request.body.title;
    ctx.body = md.setTitle(id, title);
});
koa
    .use(body({}))
    .use(router.routes())
    .use(router.allowedMethods())
    .use(Static(__dirname + '/view'))
    .use(Static(path.join(__dirname ,'../../')));

export class Admin {
    constructor(port) {
        koa.listen(port, (e) => {
            console.log(`Admin is run. port:${port}`);
            // open('http://localhost:' + port);
        });
    }
}
开发者ID:zoeDylan,项目名称:zoeDylan.github.io,代码行数:31,代码来源:index.ts


示例2: next

  if (ctx.path === '/favicon.ico') return
  ctx.session.views = (ctx.session.views || 0) + 1
  let app: any = ctx.app
  if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
  credentials: true
}))
app.use(async(ctx, next) => {
  await next()
  if (typeof ctx.body === 'object' && ctx.body.data !== undefined) {
    ctx.type = 'json'
    // ctx.body.path = ctx.path
    ctx.body = JSON.stringify(ctx.body, undefined, 2)
  }
})
app.use(async(ctx, next) => {
  await next()
  if (ctx.request.query.callback) {
    let body = typeof ctx.body === 'object' ? JSON.stringify(ctx.body, undefined, 2) : ctx.body
    ctx.body = ctx.request.query.callback + '(' + body + ')'
    ctx.type = 'application/x-javascript'
  }
})

app.use(serve('public'))
app.use(serve('test'))
app.use(body())
app.use(router.routes())

export default app
开发者ID:zerolugithub,项目名称:rap2-delos,代码行数:31,代码来源:app.ts


示例3: saveVisitList

    // record visit
    if (whiteList[ctx.request.ip] === undefined) {
      visitList[ctx.request.ip] = Date.now();
      saveVisitList();
    }

    ctx.response.status = 200;
    ctx.body = JSON.stringify({
      statistics: { ...flavor },
      code: 200
    });
  } catch (e) {
    ctx.response.status = 400;
    ctx.body = JSON.stringify(
      {
        message: e.message,
        code: 400
      },
      null,
      2
    );
  } finally {
    fs.writeFileSync("./config.json", JSON.stringify(flavor, null, 2), "utf-8");
  }
});

loadConfig();
app.use(Koabody());
app.use(router.routes()).listen(8080);
开发者ID:TeamCovertDragon,项目名称:duanwu-statistics,代码行数:29,代码来源:index.ts


示例4: next

  if (ctx.path === '/favicon.ico') return
  ctx.session.views = (ctx.session.views || 0) + 1
  let app: any = ctx.app
  if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
  credentials: true,
}))
app.use(async (ctx, next) => {
  await next()
  if (typeof ctx.body === 'object' && ctx.body.data !== undefined) {
    ctx.type = 'json'
    ctx.body = JSON.stringify(ctx.body, undefined, 2)
  }
})
app.use(async (ctx, next) => {
  await next()
  if (ctx.request.query.callback) {
    let body = typeof ctx.body === 'object' ? JSON.stringify(ctx.body, undefined, 2) : ctx.body
    ctx.body = ctx.request.query.callback + '(' + body + ')'
    ctx.type = 'application/x-javascript'
  }
})

app.use(serve('public'))
app.use(serve('test'))
app.use(bodyParser({ multipart: true }))

app.use(router.routes())

export default app
开发者ID:tonyjt,项目名称:rap2-delos,代码行数:31,代码来源:app.ts


示例5: Body

 async Body(ctx: Koa.IContext, next) {
     await Convert(_Body())(ctx, next);
 }
开发者ID:wangxin0709,项目名称:csc-scms-node-koa,代码行数:3,代码来源:controller.ts


示例6: start

    public start() {
        if (this.server) {
            return;
        }

        const self = this;
        const app = koa();

        app.use(function*(next: any): Iterator<void> {
            this.header['content-type'] =
                this.headers['content-type'] &&
                this.headers['content-type'].replace(';charset=UTF-8', '').replace(';charset=utf-8', '');

            yield next;
        });
        app.use(koaBody());
        app.use(cors());
        app.use(function*(): Iterator<void> {
            const matched = self.mockedCalls.filter(
                ({method, pathRegex, queryParamsObject, bodyRestriction = {}}: MockedCall) => {
                    if (method !== this.req.method) {
                        return false;
                    }

                    if (!new RegExp(pathRegex).test(this.url)) {
                        return false;
                    }

                    const contentTypeIsApplicationJson = this.request.header['content-type'] === 'application/json';

                    if (queryParamsObject) {
                        const splitUrl = this.url.split('?');

                        if (splitUrl.length < 2) {
                            return false;
                        }
                        const queryParamsOnUrl = queryString.parse(splitUrl[1]);

                        if (!deepEquals(queryParamsOnUrl, queryParamsObject)) {
                            return false;
                        }
                    }
                    if (bodyRestriction.regex) {
                        const requestBodyAsString = contentTypeIsApplicationJson
                            ? JSON.stringify(this.request.body)
                            : this.request.body;

                        if (!new RegExp(bodyRestriction.regex).test(requestBodyAsString)) {
                            return false;
                        }
                    }
                    if (
                        bodyRestriction.minimalObject &&
                        (!contentTypeIsApplicationJson || !isSubset(this.request.body, bodyRestriction.minimalObject))
                    ) {
                        return false;
                    }

                    if (
                        bodyRestriction.object &&
                        (!contentTypeIsApplicationJson || !deepEquals(this.request.body, bodyRestriction.object))
                    ) {
                        return false;
                    }

                    return true;
                }
            );

            if (matched.length >= 1) {
                self.callHistory.push({
                    method: this.req.method,
                    path: this.url,
                    headers: this.request.header,
                    body: this.request.body,
                });
                const firstMatch = matched[matched.length - 1];

                self.logger(
                    `fakeServer:: call to [${this.req.method} ${this.url} ${JSON.stringify(
                        this.request.body
                    )}]. Respond with status: [${firstMatch.statusCode}] and body: [${JSON.stringify(
                        firstMatch.response
                    )}]`
                );

                this.status = firstMatch.statusCode;
                this.body = firstMatch.response;
            } else {
                self.logger(
                    `fakeServer:: no match for [${this.req.method} ${this.url} ${JSON.stringify(this.request.body)}]`
                );
                this.status = 400;
                this.body = `no match for [${this.req.method} ${this.url} ${JSON.stringify(this.request.body)}]`;
            }
        });

        this.clearCallHistory();

        this.server = !this.tls
//.........这里部分代码省略.........
开发者ID:Soluto,项目名称:simple-fake-server,代码行数:101,代码来源:FakeServer.ts



注:本文中的koa-body类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript koa-bodyparser类代码示例发布时间:2022-05-28
下一篇:
TypeScript knex类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap