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) 这个简单的演示有一个错误 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) 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) 我正在学习使用dieselorm 库,我的数据库使用DECIMAL(8,2)类型,但是当我Decimal在模型中使用时,出现错误
我正在使用Decimal由rust_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) 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) 如何向所有连接的套接字发出事件?
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/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\nRun 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 }\nRun 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 }\nRun Code Online (Sandbox Code Playgroud)\n\n我查看了Swagger文档并尝试了\'@nestjs/swagger\'包中的一些api,但它不起作用。
\n我是 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].first是std::string::const_iterator,并且str.substr函数需要类型的参数int,所以我想转换result[0].first为int类型的
感谢帮助。
我在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 ×5
axios ×1
c++ ×1
javascript ×1
node.js ×1
reactjs ×1
rust ×1
rust-diesel ×1
typescript ×1
vite ×1