小编xyz*_*242的帖子

express-rate-limit - 捕获消息

在我的应用程序中,我希望能够捕获由express-rate-limit 包生成的消息。这是我的代码示例。我希望能够使用中间件捕获消息部分,以便我可以对其进行后处理(在本例中我有多种语言)。

const apiCreatingAccountLimiter = rateLimit({
  windowMs: 10 * 60 * 1000, // 10 minutes
  max: 10, // limit each IP to 10 requests per windowMs
  message: {
    limiter: true,
    type: "error",
    message: 'maximum_accounts'
  }
});

Run Code Online (Sandbox Code Playgroud)

进而

router.post('/signup', apiCreatingAccountLimiter, (req, res, next) => {
// handling the post request
})
Run Code Online (Sandbox Code Playgroud)

我为其他一些 API 消息设置了类似的解决方案中间件:

// error processing middleware
app.use((err, req, res, next) => {
    const statusCode = err.statusCode || 500;
    res.status(statusCode).send({
        type: 'error', 
        message: err.message, 
        fields: err.fields === '' ? '' …
Run Code Online (Sandbox Code Playgroud)

middleware node.js express

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

如何在 Flutter 中的框装饰图像上添加不透明叠加层

我正在努力为这个看似简单的任务找到解决方案。我需要在 Flutter 中的图像上覆盖不透明的图层。我尝试过以不同的方式添加叠加层,但图像始终会叠加在我所做的任何事情之上。请注意,我需要在图像上覆盖不透明的覆盖层,但不需要位于图像和覆盖层之上的标题或文本。或者,我可以使用黑色背景并使图像不透明,从而可能达到我想要实现的相同效果?在我开始进行过多的黑客攻击之前,我想看看专业人士是如何以应有的方式做这件事的。谢谢大家的好意建议。

                  Container(
                    width: 320.0,
                    height: 180.0,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: NetworkImage(
                            news[index]['jetpack_featured_media_url'],
                        ),
                        fit: BoxFit.cover,
                      ),
                      color: Color(0xFF1F1F98),
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        colors: [Colors.black, Colors.black],
                        stops: [0.0, 0.5]
                      ),
                      borderRadius: new BorderRadius.only(
                          topLeft: const Radius.circular(8.0),
                          topRight: const Radius.circular(8.0)
                      ),
                    ),
                    child: Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: Text(
                            cardTitle(news[index]['title']['rendered']),
                            style: kCardOverlayTitleTextStyle
                        )
                    ) /* add child content here */,
                  ),
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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

React vis - 在 x 轴上格式化时间刻度

我已将 加到xType="time"图表中以在 x 轴上显示时间刻度。我只显示 25 秒范围内的数据。目前,x 轴将时间格式显示为:SS

因此 x 轴以以下格式显示时间(数据显示每秒):

:23, :24, :25

我从数据库中得到的是以下格式的时间字符串: 2019-07-01T10:42:38.621Z

我尝试了以下方法:

new Date(item.date) // shows ':023'
new Date(item.date).getTime() // shows ':023'
new Date(item.date.substring(19, 0)).getTime() // shows ':023'
Run Code Online (Sandbox Code Playgroud)
    oscilloscope.oscilloscope.map((item, index) => {
        return {
            x: new Date(item.date.substring(19, 0)).getTime(),
            y: item.data.fuelInjection
        }
    })
Run Code Online (Sandbox Code Playgroud)

总是得到相同的结果。

我希望 x 轴按格式进行HH:MM:SS格式化。

所以 x 轴显示的数据如下: 11:42:05, 11:42:06, 11:42:07

我显示的范围相隔 25 秒。这似乎是由图表自动设置的,就好像我将范围更改为包含几分钟的范围,x 轴上的时间显示更改为MM:SS格式。我仍然需要HH:MM:SS你的格式。这完全可以做到吗?

react-vis

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

使用 Jest 和 Enzyme @react-google-maps/api 进行 React 测试返回 TypeError:无法读取未定义的属性“maps”

我正在尝试使用@react-google-maps/api包测试组件。我收到错误:TypeError: Cannot read property 'maps' of undefined

我的组件:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { fetchPersonId, updatePersonSettings, pushPersonMessage } from '../../actions/person';
import TemplatePage from '../templates/TemplatePage';
import Card from '../partials/Card';
import Msg from '../partials/Msg';
import { GoogleMap, Marker } from '@react-google-maps/api';
import markerPosition from'../../img/marker-position.png';
import PlacesAutocomplete, { geocodeByAddress, getLatLng } from 'react-places-autocomplete';
import PropTypes from 'prop-types';
import { DEFAULT_LAT, DEFAULT_LNG, DEFAULT_ZOOM } from '../../config/';


export class Settings extends Component …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme

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

React Typescript socket.io-client io.connect 上的 Typescript 错误

我正在使用 React Typescript 和 socket.io-client 4.0.0 和 @types/socket.io-client 3.0.0。就代码而言,一切都很好:

socket = io.connect(`ws://${WS_DOMAIN}:${WS_PORT}`, { transports: ["websocket"] });
Run Code Online (Sandbox Code Playgroud)

我在 io.connect 上收到以下错误:

any
Property 'connect' does not exist on type '{ (opts?: Partial<ManagerOptions &
SocketOptions> | undefined): Socket<DefaultEventsMap, DefaultEventsMap>; (uri: string, 
opts?: Partial<...> | undefined): Socket<...>; (uri: string | Partial<...>, opts?: 
Partial<...> | undefined): Socket<...>; }'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

我希望错误消失,但当然,我不知道如何消除它。这是我的 tsx 文件中唯一的错误。

值得一提的是,这是一个基于类的组件。IO 的导入方式如下:

import { io } from 'socket.io-client';
Run Code Online (Sandbox Code Playgroud)

并且类型在类初始化之前分配:

let socket: any;
Run Code Online (Sandbox Code Playgroud)

socket.io typescript reactjs

3
推荐指数
2
解决办法
4959
查看次数