如何使用方式nest.js 编写标题?
我目前正在使用这个:
import { Controller, Body, Get, Post, HttpCode, HttpStatus, Req, Res } from '@nestjs/common';
import { Request, Response } from 'express';
import { AuthService } from './auth.service';
import { Usuario } from '../usuario/usuario.entity';
import { JsonWebTokenError } from 'jsonwebtoken';
import { request } from 'http';
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) { }
@Post('login')
@HttpCode(HttpStatus.OK)
async login(@Body('username') username: string, @Body('password') password: string, @Res() response: Response) {
this.authService
.validateUser(username, password)
.then((token) => {
response.setHeader('Authorization', 'Bearer ' + token);
let respuesta: any = {};
respuesta.success = true;
respuesta.token = token;
return response.send(respuesta);
});
}
}
我不想使用response.setHeader('Authorization', 'Bearer ' + token);
和return response.send(respuesta);
感谢您的回答!