小编cod*_*ess的帖子

在 SQS 中为无服务器启用静态加密

我们正在为我们的应用程序使用无服务器框架和微服务(lambda 函数)。在 serverless.yml 文件中,我们列出了部署时需要创建的资源。

serverles.yml 文件的资源部分如下所示:

resources:
    Resources:
        GatewayResponse:
            Type: "AWS::ApiGateway::GatewayResponse"
            Properties:
                ResponseParameters:
                    gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
                    gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
                ResponseType: EXPIRED_TOKEN
                RestApiId:
                    Ref: "ApiGatewayRestApi"
                StatusCode: "401"
        AuthFailureGatewayResponse:
            Type: "AWS::ApiGateway::GatewayResponse"
            Properties:
                ResponseParameters:
                    gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
                    gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
                ResponseType: UNAUTHORIZED
                RestApiId:
                    Ref: "ApiGatewayRestApi"
                StatusCode: "401"
        SqsQueue:
            Type: "AWS::SQS::Queue"
            Properties:
                QueueName: ${opt:stage}-${opt:product}-sqs-queue
                VisibilityTimeout: 900
                RedrivePolicy:
                    deadLetterTargetArn:
                        Fn::GetAtt:
                        - SqsDeadLetterQueue
                        - Arn
                    maxReceiveCount: 1
        SqsDeadLetterQueue:
            Type: AWS::SQS::Queue
            Properties:
                QueueName: ${opt:stage}-${opt:product}-deadletter-queue
                MessageRetentionPeriod: 1209600
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我们也在那里创建 SQS 队列资源。最初,我们没有在 SQS 中启用静态加密,但现在出现了这种需求。

我可以进入 AWS 控制台并从那里为我们创建的每个队列手动启用静态加密,但这会很乏味,而且我想将其包含在 serverless.yml 创建中,以便从现在开始创建的任何 SQS 资源都具有默认启用加密。

我想知道需要添加到 serverless.yml 的资源部分中。我是否添加 …

encryption amazon-sqs amazon-web-services aws-cloudformation

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

在Node.js和Express中处理404、500和异常

我有一个node.js + Express + express-handlebars应用程序。我想将用户转到不存在的页面时将用户重定向到404页面,并在出现内部服务器错误或异常(不停止服务器)时将其重定向到500。在我的app.js中,我最后编写了中间件来执行这些任务。

app.get('*', function(req, res, next) {
    var err = new Error();
    err.status = 404;
    next();
});

//Handle 404
app.use(function(err, req, res, next){
    res.sendStatus(404);
    res.render('404');
    return;
});

//Handle 500
app.use(function(err, req, res, next){
    res.sendStatus(500);
    res.render('500');
});

//send the user to 500 page without shutting down the server
process.on('uncaughtException', function (err) {
  console.log('-------------------------- Caught exception: ' + err);
    app.use(function(err, req, res, next){
        res.render('500');
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,只有404的代码有效。因此,如果我尝试转到网址

localhost:8000/fakepage
Run Code Online (Sandbox Code Playgroud)

它成功将我重定向到我的404页面。505不起作用。对于异常处理,服务器确实保持运行,但是在console.log之后,它不会将我重定向到500错误页面。

如此众多的在线解决方案让我感到困惑,因为人们似乎为此采用了不同的技术。

这是我看过的一些资源

http://www.hacksparrow.com/express-js-custom-error-pages-404-and-500.html

正确处理快递中的404和500错误的方法

如何将404错误重定向到ExpressJS中的页面?

https://github.com/expressjs/express/blob/master/examples/error-pages/index.js

javascript node.js express

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

即使属性存在,Node.js hasOwnProperty 也不起作用

在我的 Node.js Express 应用程序中,当用户通过护照登录时,用户用户对象将保存在请求中。

它看起来像这样:

{
    "uuid": "caa5cb58-ef92-4de5-a419-ef1478b05dad",
    "first_name": "Sam",
    "last_name": "Smith",
    "email": "sam@email.com",
    "password": "$2a$10$fXYBeoK6s.A8xo2Yfgx4feTLRXpdvaCykZxr7hErKaZDAVeplk.WG",
    "profile_uuid": "db172902-f3c9-456d-8814-53d07d4ea954",
    "isActive": true,
    "deactivate": false,
    "verified": true,
    "ProviderUuid": "7149f8f1-0208-41db-a78e-887e7811a169"
}
Run Code Online (Sandbox Code Playgroud)

但并非每个用户都有 ProviderUuid 密钥。因此,在使用其值之前,我尝试检查 ProviderUuid 键是否存在于用户对象中

var user = req.user;
console.log('---- provider: ' + JSON.stringify(user));
console.log('--- prop: ' + user.hasOwnProperty('ProviderUuid')); //returns false
console.log('---- other method prop check: ' + Object.prototype.hasOwnProperty.call(user, "ProviderUuid")); //returns false
if('ProviderUuid' in user){
    //this returns true
}
Run Code Online (Sandbox Code Playgroud)

这样做user.hasOwnProperty('ProviderUuid')并Object.prototype.hasOwnProperty.call(user, "ProviderUuid"))返回 false,但'ProviderUuid' in user返回 true。

我在这里缺少什么?

javascript node.js hasownproperty

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

vue-chartjs 无法渲染折线图

MyChart.vue

<template>
  <v-container>
    <v-card elevation="2">
      <v-card-title>AQI Comparison</v-card-title>
      <line-chart :chart-data="datacollection"></line-chart>
    </v-card>
  </v-container>
</template>

<script>
import LineChart from "./LineChart.js";

export default {
  name: "AQIChartComponent",
  components: {
    LineChart
  },
  data() {
    return {
      datacollection: {
        labels: [
          "week 1",
          "week 2",
          "week 3",
          "week 4",
          "week 5",
          "week 6",
          "week 7",
          "week 8",
          "week 9",
          "week 10",
        ],
        datasets: [
          {
            data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478],
            label: "Africa",
            borderColor: "#3e95cd",
            fill: false,
          },
          {
            data: [282, 350, …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-chartjs

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

通过 DNS 为 Route53 颁发证书时,Certbot 无法找到 AWS 凭证

我需要从 LetsEncrypt 获取 AWS Route 53 上托管的域的证书。我没有暴露任何端口 80 或 443,因为服务器用于 VPN 并且没有公共访问权限。

因此,实现此目的的唯一方法是通过路由 53 的 DNS 验证。

到目前为止我已经安装了 certbot 和 dns-route53 插件

sudo snap install --beta --classic certbot
sudo snap set certbot trust-plugin-with-root=ok
sudo snap install --beta certbot-dns-route53
sudo snap connect certbot:plugin certbot-dns-route53
Run Code Online (Sandbox Code Playgroud)

我在我的 AWS 账户中创建了一个可以访问 Route53 的特殊用户,并且在 ~/.aws/config 和 ~/.aws/credentials 中添加了访问密钥 id 和秘密访问密钥,如下所示

[default]
aws_access_key_id=foo
aws_secret_access_key=bar
Run Code Online (Sandbox Code Playgroud)

基本上遵循此处给出的每个步骤:https ://certbot-dns-route53.readthedocs.io/en/stable/

现在,当我运行以下命令时:

sudo certbot certonly -d mydomain.com --dns-route53
Run Code Online (Sandbox Code Playgroud)

它给出以下输出:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator dns-route53, Installer None
Requesting …
Run Code Online (Sandbox Code Playgroud)

dns ssl amazon-route53 lets-encrypt certbot

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

图表js旧图表数据未清除

这个问题已经被问过很多次了,我经历了其中的大部分,但没有一个能帮助我找到解决方案。

我正在使用 for 循环生成几个条形图作为报告功能的一部分。

我正在使用带有 Express Handlebars 的 node.js。

我的页面看起来像:

<div class="row report-charts">
    <div class="col-md-12">
    {{#buildings}}
        <div class="col-md-6">
           <h4>{{Name}}</h4>
           <canvas id="{{idBuildings}}" width="200" height="80"></canvas>
        </div>
    {{/buildings}}
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的 js 代码如下所示:

$('.case-report-btn').click(function(){

        $.ajax({
            type: 'post',
            url: '/reports/cases/filter',
            data : {
                StartDate : $('.start-ms-time-hidden').val(),
                EndDate : $('.end-ms-time-hidden').val(),
                ReportKey : $('.cases-filter-type').val()
            },
            dataType: 'json',
            success: function(res) {
                $('.report-charts').show();
                for(key in res) {
                    var innerObj = res[key]; //gives the inner obj
                    var ctx = document.getElementById(key); //the idBuildings
                    var labels = [];
                    var data = …
Run Code Online (Sandbox Code Playgroud)

javascript jquery node.js chart.js

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

随机数生成器生成重复项

框架:Java

public static List<Integer> buttonIdList = new ArrayList();

public void myMainMethod() {
   for(Integer i = 0; i < 11; i++) {
      int randomButtonId = getUniqueIdNumber();
   }
}

private static Integer getUniqueIdNumber() {
        Random ran = new Random();
        int randomButtonId = ran.nextInt(20) + 1;

        if(buttonIdList.contains(randomButtonId)) {
            getUniqueIdNumber();
        } else {
            buttonIdList.add(randomButtonId);
        }

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

当代码遇到重复时,它会自动调用(递归),在第二次尝试时,如果数字是唯一的,则return语句将其返回给myMainMethod或getUniqueIdNUmber?

退货声明应该放在哪里?

java random recursion

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