小编jan*_*w a的帖子

React router v6 如何在 axios 拦截器中使用“navigate”重定向

import axios from "axios";
import { useNavigate } from "react-router-dom";

export const api = axios.create({
  baseURL: "http://127.0.0.1:8000/",
  headers: {
    "content-type": "application/json",
  },
});

api.interceptors.response.use(
  function (response) {
    return response;
  },
  function (er) {
    if (axios.isAxiosError(er)) {
      if (er.response) {
        if (er.response.status == 401) {

          // Won't work
          useNavigate()("/login");

        }
      }
    }

    return Promise.reject(er);
  }
);
Run Code Online (Sandbox Code Playgroud)

reactjs react-router-dom

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

Nestjs 使用 axios

这个简单的演示有一个错误 https://docs.nestjs.com/techniques/http-module

import { Get, Controller, HttpService } from '@nestjs/common';
import { AxiosResponse } from 'axios'
import { Observable } from 'rxjs'
@Controller()
export class AppController {
  constructor(private readonly http: HttpService) {}
  @Get()
  root(): Observable<AxiosResponse<any>>  {
    return this.http.get('https://api.github.com/users/januwA');
  }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

[Nest] 7356   - 2018-10-18 00:08:59   [ExceptionsHandler] Converting circular structure to JSON +9852ms
TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
Run Code Online (Sandbox Code Playgroud)
nest i
common version : 5.1.0
core version   : 5.1.0
Run Code Online (Sandbox Code Playgroud)

javascript node.js axios nestjs

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

为什么vite中不能使用reflect-metadata

import "reflect-metadata"

function validate(target: any) {
  let paramtypes = Reflect.getMetadata("design:paramtypes", target);
  console.log(paramtypes);  // undefined
}

@validate
class Log {
  constructor(public readonly xx: string) {}
}
Run Code Online (Sandbox Code Playgroud)

打我启动服务器,打开网页发现paramtypes未定义

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": false,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "include": ["./src"]
}
Run Code Online (Sandbox Code Playgroud)

typescript reflect-metadata vite

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

铁锈:正确使用柴油中的十进制类型

我正在学习使用dieselorm 库,我的数据库使用DECIMAL(8,2)类型,但是当我Decimal在模型中使用时,出现错误

我正在使用Decimalrust_decimal

diesel = { version="1.4.8", features = ["mysql", "r2d2", "chrono", "numeric"] }

rust_decimal =  { version ="1.23", features = ["serde-with-str", "db-diesel-mysql"] }
rust_decimal_macros = "1.23"
Run Code Online (Sandbox Code Playgroud)

我的 mysql 表

diesel = { version="1.4.8", features = ["mysql", "r2d2", "chrono", "numeric"] }

rust_decimal =  { version ="1.23", features = ["serde-with-str", "db-diesel-mysql"] }
rust_decimal_macros = "1.23"
Run Code Online (Sandbox Code Playgroud)

柴油发电模式

CREATE TABLE `books` ( 
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 
    `name` VARCHAR(20) NOT NULL , 
    `price` …
Run Code Online (Sandbox Code Playgroud)

rust rust-diesel

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

nestjs如何在请求中获取Cookie?

nestjs如何在请求中获取Cookie?

import { Get, Controller, Response, Request } from '@nestjs/common';
import { AppService } from './app.service';

const l = console.log
@Controller()
export class AppController {
  @Get('json')
  json(@Request() req){
    console.log(req.cookies) // undefined
  }
}
Run Code Online (Sandbox Code Playgroud)

nestjs

5
推荐指数
3
解决办法
2897
查看次数

Nestjs 网关向所有连接的套接字发出事件

如何向所有连接的套接字发出事件?

    export class EventsGateway {

      @SubscribeMessage('message')

       async onEvent(client, data) {
        // The following is the use of `socket.io` to issue events to all connected sockets.
        // io.emit('message', data);
      }
    }
Run Code Online (Sandbox Code Playgroud)

我如何在nestjs中执行此操作?

nestjs

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

Nestjs 如何使用 @nestjs/swagger 生成有关 Passport 策略路线的文档

我正在使用@nestjs/swagger来生成 api 文档。但是如何为经过身份验证的路由生成文档呢?

\n\n

巢版

\n\n
\xce\xbb nest i\nNodeJS Version : v10.16.0\n[Nest Information]\nplatform-express version : 6.0.0\npassport version         : 6.1.0\nswagger version          : 3.1.0\ncommon version           : 6.0.0\ncore version             : 6.0.0\njwt version              : 6.1.1\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是正常的路线,我可以使用“@ApiImplicitBody”来制作文档:

\n\n
  @Delete()\n  @ApiImplicitBody({\n    name: \'id\',\n    required: true,\n    type: String,\n  })\n  @ApiOkResponse({\n    description: \'successfully deleted\',\n  })\n  delete(@Body(\'id\') typeId) {\n    return this.typesService.delete(typeId);\n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

该路由需要身份验证,我如何记录此类路由?

\n\n
  @UseGuards(AuthGuard(\'local\'))\n  @Post(\'login\')\n  @ApiOkResponse({\n    description: \'result Token\',\n  })\n  async login(@Request() req) {\n    return this.authService.login(req.user);\n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

我查看了Swagger文档并尝试了\'@nestjs/swagger\'包中的一些api,但它不起作用。

\n

nestjs

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

如何在 C++ 中将 std::string::const_iterator 类型转换为 int 类型

我是 C++ 的新手

想用c++实现字符串拆分功能,所以写了如下代码:

#include <vector>
#include <regex>
#include <sstream>
#include <string>

    std::string str = "1:2-3:4";
    std::smatch result;
    std::regex pattern("[:-]");

    std::string::const_iterator iterStart = str.begin();
    std::string::const_iterator iterEnd = str.end();


    std::vector<std::string> splitList = {};
    while (regex_search(iterStart, iterEnd, result, pattern))
    {
        // If std::string::const_iterator provides the int attribute
        // splitList.push_back(str.substr(iterStart.int, result[0].first.int));

        iterStart = result[0].second;
    }
Run Code Online (Sandbox Code Playgroud)

的类型result[0].firststd::string::const_iterator,并且str.substr函数需要类型的参数int,所以我想转换result[0].firstint类型的

感谢帮助。

c++

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

nestjs 如何在项目中配置路径别名

我在nestjs项目的tsconfig.json中配置了路径别名,但是运行时出现错误。

我尝试像Angular一样配置,但是nestjs出现错误

这是我的 tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "paths": {
      "~auth/*": ["src/auth/*"]
    }
  },
  "exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)

像这样使用它

import { userLoginJwt } from '~auth/jwt-names'
Run Code Online (Sandbox Code Playgroud)

启动错误

$ npm run start:dev
[0] internal/modules/cjs/loader.js:584
[0]     throw err;
[0]     ^
[0]
[0] Error: Cannot find module 'src/auth/jwt-names'
Run Code Online (Sandbox Code Playgroud)

抱歉,我在此强调,跑步npm run start是没问题的,但是跑步npm run start:dev会导致意想不到的情况。

nestjs

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