我有以下代码:
import { IsNotEmpty, IsArray, ArrayMinSize } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class PublishDto {
@IsNotEmpty()
@IsArray()
@ArrayMinSize(1)
@ApiProperty({
type: [Product]
})
products: Product[];
}
interface Product {
id: string;
title: string;
sku: string;
stock: number;
description: string;
shortDescription: string;
imagesUrl: string[];
price: number;
department: string;
category: string;
brand: string;
keywords: string[];
isActive: boolean;
}
Run Code Online (Sandbox Code Playgroud)
我试图将接口Product作为 swagger 上的模式,但它不起作用,我收到错误。任何想法?
我运行并设置了这个 Nest.js 应用程序一段时间,突然间,当我运行npm run build时,它开始报告此情况。
node_modules/@nestjs/config/dist/config.service.d.ts:1:23 - error TS2305: Module '"./types"' has no exported member 'Path'.
1 import { NoInferType, Path, PathValue } from './types';
~~~~
node_modules/@nestjs/config/dist/config.service.d.ts:1:29 - error TS2305: Module '"./types"' has no exported member 'PathValue'.
1 import { NoInferType, Path, PathValue } from './types';
~~~~~~~~~
node_modules/@nestjs/config/dist/types/path-value.type.d.ts:1:114 - error TS1005: '?' expected.
1 export declare type PathImpl<T, Key extends keyof T> = Key extends string ? T[Key] extends Record<string, any> ? `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & …Run Code Online (Sandbox Code Playgroud) 我安装了 Nest.js。当我运行 npm run start:dev (运行 start --watch)时,一切正常并且出现绿色日志。
问题是,当我更新代码中的某些内容时,nest 不再更新,并且卡在下图中:
我确信这不是我的代码的问题,因为我在所有的 Nest.js 存储库中都遇到了同样的问题。我还删除了node_modules并重新安装它们,但它不起作用。
我还尝试在全局范围内重新安装 Nest CLI。
我的节点版本是16.5.0和npm 8.5.0
这是我的 package.json:
{
"name": "unigow-backend",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "env-cmd -f .env.production rimraf dist",
"build": "env-cmd -f .env.production nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "env-cmd -f .env.development nest start --watch",
"start:debug": "env-cmd -f .env.development nest start --debug --watch",
"start:prod": "env-cmd -f .env.production node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", …Run Code Online (Sandbox Code Playgroud) 我几个小时前才开始学习 C#,但后来遇到了这个错误。
Ctrl + Shift + P
.NET:生成用于构建和调试的资产
但是当我点击它时,窗口右下角会弹出一个错误:
找不到 .NET Core 项目。未生成资产。
以配置为例,Nest.js 文档提倡注册 Config Module,并以依赖注入的方式将其注入到其他模块中。
好处很明显,依赖和代码也清晰,但是如果我有一个nest.js项目需要在启动时调用配置信息怎么办?这实际上给我带来了麻烦。
我的想法是使用一个store(实际上是一个闭包)来管理全局可能需要的所有变量,客户端链接对象,在启动时注册,并在需要时引入。
当相应的变量以这种方式注册后,就可以在任何地方引入它们。缺点是您需要自己管理依赖关系。
以上demo概念设计: https: //github.com/sophons-space/nest-server。
请大家帮我指正,我还是个菜鸟。
管道有两种使用方式
@Param('foo', MyPipe)它MyPipe在框架中创建
或者我可以做@Param('foo', new MyPipe())。
解决方案 1 使我能够使用@Injectable我需要的内容(例如,我注入 db 来从数据库解析用户)
但是,我无法访问构造函数,因此无法配置管道。
在场景2中我可以配置它,但我不能使用Injectable
有没有办法例如在这个范围内使用一些工厂,这样我就可以像在模块中创建它一样构造管道?
在本地机器上一切正常。部署后问题就出现了。部署后,/querybuilder将附加到基本 url。所以,
http://localhost:80/helloworld
Run Code Online (Sandbox Code Playgroud)
会成为
http://52.xxx.xxx.139/querybuilder/helloworld
Run Code Online (Sandbox Code Playgroud)
Swagger 页面位于:
http://52.xxx.xxx.139/querybuilder/swagger/
当我通过 swagger ui 页面执行方法时:这是我在网络选项卡中看到的:
控制器:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
Run Code Online (Sandbox Code Playgroud)
主.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('Query Builder - MongoDb Parser')
.setDescription("This is Query Builder's MongoDb Parser takes database agnostic queries and transpiles it into native MongoDb query.")
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', …Run Code Online (Sandbox Code Playgroud) 当尝试连接到 SQL Server 时,出现以下错误:
[Nest] 96151 - 30/07/2021 18:28:34 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
ConnectionError: Failed to connect to XXXXXX:1433 - self signed certificate*
Run Code Online (Sandbox Code Playgroud)
我的 ormconfig.json:
[Nest] 96151 - 30/07/2021 18:28:34 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
ConnectionError: Failed to connect to XXXXXX:1433 - self signed certificate*
Run Code Online (Sandbox Code Playgroud) 在Startup.cs我添加api/到我的路线模式的开始。
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "api/{controller}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情:旧的 URL 继续工作,并且以 return 404 开头的 URL 继续工作。/api这没有任何意义!
如何让我的 API 在 下提供服务/api?
在联合嵌套应用程序中,网关收集来自其他服务的所有架构并形成完整的图。问题是,子模式更改后如何重新运行模式集合?
重新启动网关可以解决问题,但这似乎不是一个优雅的解决方案。
我试图理解编译器/解释器/内核为你做的所有低级东西(因为我是另一个认为他们可以设计出比大多数其他语言更好的语言的人)
引发我好奇的众多事物之一是 Async-Await。我检查了几种语言的底层实现,包括 C#(编译器从糖代码生成状态机)和 Rust(状态机必须从 Future trait 手动实现),它们都使用状态机实现 Async-Await。通过谷歌搜索(“异步复制堆栈框架”和变体)或“类似问题”部分,我没有发现任何有用的东西。
对我来说,这种方法似乎相当复杂且开销很大;
你不能通过简单地将异步调用的堆栈帧内存复制到/从堆来实现 Async-Await 吗?
我知道某些语言在架构上是不可能的(我感谢 CLR 做不到,所以 C# 也做不到)。
我是否错过了使这在逻辑上不可能的东西?我希望通过这种方式实现更简单的代码和性能提升,我错了吗?我想当你在异步调用(例如递归异步函数)之后有一个很深的堆栈层次结构时,你需要 memcopy 的数据量相当大,但可能有办法解决这个问题。
如果这是可能的,那么为什么不在任何地方完成?
language-agnostic compiler-construction asynchronous async-await
nestjs ×8
node.js ×4
swagger ×2
typescript ×2
.net-core ×1
asp.net-core ×1
async-await ×1
asynchronous ×1
c# ×1
global ×1
graphql ×1
javascript ×1
swagger-ui ×1
typeorm ×1