在最新的 Node 16.8 中,导入时必须使用文件扩展名(例如import { getFoo } from './api.js';)。同时 ESLint 抛出错误Unexpected use of file extension "js" for "./api.js"。
这是我的配置文件:
module.exports = {
env: {
node: true,
es2021: true,
},
extends: [
'airbnb-base',
],
parserOptions: {
ecmaVersion: 12,
},
rules: {
'no-console': 'off',
},
};
Run Code Online (Sandbox Code Playgroud)
目前最好的做法是什么?或者至少是最好的解决方案?
如果没有,我至少可以禁用该规则吗?
在 中ASP.NET Core 3.0 Web API,我对和方法使用相同的DTO。在创建新名称时,我想防止已经存在的名称。像这样:PostPutItem
public ItemValidator(IItemRepository itemRepository)
{
RuleFor(input => input.Name).NotEmpty();
RuleFor(input => input.Name).Must(name => !itemRepository.ItemExists(name))
.WithMessage(input => $"Item '{input.Name}' already exists");
}
Run Code Online (Sandbox Code Playgroud)
这一切都非常适合更新和插入。您不能将名称更新为已存在的名称。但!当您尝试将“ItemA”更改为“ItemA”(新名称与旧名称相同)时,您会收到该错误,并且可能会有点误导(尽管在技术上是正确的)。
在dto本身中,我没有唯一id的项目。因为我id在路上经过。
如果我可以访问已调用的控制器方法及其参数(包括id),我将能够判断是否有人试图将项目名称更改为相同名称。
c# fluentvalidation .net-core asp.net-core asp.net-core-webapi
我有一个简单的.NET Core WebAPI没有身份验证的。我使用默认策略添加了 Cors。我从 React 网站或 Postman 连接和获取数据没有问题(一切都在我的机器上本地运行)。现在,我尝试在超级简单的node应用程序中从该 API 获取数据,但收到此错误:
file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
^
FetchError: request to https://localhost:5001/api/teams failed, reason: self signed certificate
at ClientRequest.<anonymous> (file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94:11)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'DEPTH_ZERO_SELF_SIGNED_CERT',
code: 'DEPTH_ZERO_SELF_SIGNED_CERT',
erroredSysCall: undefined
}
Run Code Online (Sandbox Code Playgroud)
这是我的整个node申请:
import fetch from 'node-fetch';
async function fetchTeams() {
const response = await …Run Code Online (Sandbox Code Playgroud) javascript certificate node.js asp.net-web-api asp.net-core-webapi
javascript ×2
node.js ×2
.net-core ×1
asp.net-core ×1
c# ×1
certificate ×1
ecmascript-6 ×1
eslint ×1