小编wzr*_*337的帖子

节点8 + Typescript + Koa + koa-Router抛出"TypeError:ctx.onerror不是函数"

我有一个非常简单的服务器可以玩:

import * as http from 'http';
import * as Koa from "koa";
import { Request, Response, Context } from "koa";
import * as Router from "koa-router";
import * as bodyParser from "koa-bodyparser";

const HTTPPORT = 3000;

var app:Koa = new Koa();
var router:Router = new Router();

app.use(async (ctx:Context, next)=> {
  console.log(ctx);
  return await next();
});

router.get('/', function (ctx) {
  ctx.body = "hello world";
  console.log("success")
});

app
  .use(bodyParser)
  .use(router.routes())
  .use(router.allowedMethods());

const  httpServer = http.createServer(app.callback());
//listen on provided port
httpServer.listen(HTTPPORT, () …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript koa koa-router

4
推荐指数
1
解决办法
804
查看次数

如何在 Cloudformation 模板/CDK 中添加 AWS IoT 配置模板

我正在使用 Cloudformation 模板创建一个堆栈,包括 IoT 车队配置模板,并根据 文档,IoT 配置模板主体应该是字符串类型。

我有这样的物联网车队配置模板:

{
  "Parameters": {
    "SerialNumber": {
      "Type": "String"
    },  
    "AWS::IoT::Certificate::Id": {
      "Type": "String"
    }
  },
  "Resources": {
    "certificate": {
      "Properties": {
        "CertificateId": {
          "Ref": "AWS::IoT::Certificate::Id"
        },
        "Status": "Active"
      },
      "Type": "AWS::IoT::Certificate"
    },
    "policy": {
      "Properties": {
        "PolicyName": "mypolicy"
      },
      "Type": "AWS::IoT::Policy"
    },
    "thing": {
      "OverrideSettings": {
        "AttributePayload": "MERGE",
        "ThingGroups": "REPLACE",
        "ThingTypeName": "REPLACE"
      },
      "Properties": {
        "AttributePayload": {       
          "SerialNumber": {
            "Ref": "SerialNumber"
          }          
        },             
        "ThingName": {
          "Ref": "SerialNumber"
        }
      },
      "Type": "AWS::IoT::Thing"
    } …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation iot

3
推荐指数
1
解决办法
494
查看次数

在 Rust 中使用可选的 JSON 字段,避免在 JSON 中使用 None / null,而是使用 undefined

除了这个之外,还有更好(更精简)的方式来表达我自己:

#[derive(Serialize, Deserialize, Debug, Default]
pub struct PagingObject {
  #[serde(skip_serializing_if = "Option::is_none")]
  offsetId: Option<String>,     // offset expressed as element id (uuid)
  #[serde(skip_serializing_if = "Option::is_none")]
  offset: Option<i32>,          // offset expressed as index (numeric)
  #[serde(skip_serializing_if = "Option::is_none")]
  total: Option<i32>,           // total number of elements
  #[serde(skip_serializing_if = "Option::is_none")]
  totalPages: Option<i32>,      // total number of pages based on limit
  #[serde(skip_serializing_if = "Option::is_none")]
  previous: Option<String>,     // link to previous page
  #[serde(skip_serializing_if = "Option::is_none")]
  next: Option<String>,         // link to next page
  #[serde(skip_serializing_if = "Option::is_none")]
  limit: Option<i32> …
Run Code Online (Sandbox Code Playgroud)

json rust serde

3
推荐指数
1
解决办法
3471
查看次数

我应将哪种类型的TypeTypescript的AWS Lambda响应返回给AWS API网关方法响应套件?

我想在AWS lambda上构建适当的打字稿项目。

现在,我有以下定义:

export type HttpResponse = {
  statusCode: number;
  headers: {};
  body: string;
}

export async function readCollection (event, context, callback): Promise<HttpResponse>{

  console.log(event); // Contains incoming request data (e.g., query params, headers and more)

  const data =  [
    {
      id: "a7b5bf50-0b5b-11e9-bc65-6bfc39f23288",
      name: "some thing",
      uri: `/notifications/a7b5bf50-0b5b-11e9-bc65-6bfc39f23288`
    }
  ]

  const response = {
    statusCode: 200,
    headers: {
    },
    body: JSON.stringify({
      status: "ok",
      data: data
     })
  };

  return response;
};
Run Code Online (Sandbox Code Playgroud)

除了使用自定义HttpResponse类型,我还想使用一个官方定义。

但是我要导入和返回哪种正式类型?

typescript aws-lambda aws-api-gateway

1
推荐指数
2
解决办法
1329
查看次数

将字符串的值限制为 Rust 中的某个集合

如何将字符串的值限制为 Rust 中的某个集合?

\n
// string literal union type with\n// values of "admin", "owner", "user"\ntype Roles = "admin" | "owner" | "user";\n\n// use the type "Roles" for the "role" variable\nlet role: Roles;\n\n// assing a value other than "admin", "owner", "user"\nrole = "Hello World!"; // \xe2\x9d\x8c not allowed. Type \'"Hello World!"\' is not assignable to type \'Roles\'\n\n// assign a valid string value\nrole = "admin"; // \xe2\x9c\x85 allowed.\n
Run Code Online (Sandbox Code Playgroud)\n

锈的等价物是什么

\n

string rust

1
推荐指数
1
解决办法
692
查看次数

如何删除iOS 7中的状态栏

如何删除iOS7中的状态栏?

我有一个iOS6的全屏应用程序没有状态栏,上iOS7显示半透明sytle新的状态栏.

cordova ios7

0
推荐指数
1
解决办法
3562
查看次数