Skip to content

Commit

Permalink
fix: 🐛 get request not send body
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Jun 25, 2024
1 parent 2ff8f25 commit 14fed12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 4 additions & 4 deletions apps/be/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from 'express';
import { Controller, Get, Req, Res } from '@nestjs/common';
import { Response } from 'express';
import { Controller, Get, Res } from '@nestjs/common';

import { AppService } from './app.service';

Expand All @@ -8,7 +8,7 @@ export class AppController {
constructor(private readonly appService: AppService) {}

@Get('/ping')
getPing(@Req() req: Request, @Res() res: Response) {
return this.appService.getPing(req, res);
getPing(@Res() res: Response) {
return this.appService.getPing(res);
}
}
9 changes: 3 additions & 6 deletions apps/be/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Request, Response } from 'express';
import { Response } from 'express';
import { Injectable } from '@nestjs/common';
import { format } from 'date-fns/format';
import { toZonedTime } from 'date-fns-tz';

@Injectable()
export class AppService {
getPing(req: Request, res: Response) {
const zonedDate = toZonedTime(
new Date(),
req.body['tz'] || process.env['TZ'] || 'Asia/Ho_Chi_Minh',
);
getPing(res: Response) {
const zonedDate = toZonedTime(new Date(), process.env?.TZ || 'Asia/Ho_Chi_Minh');
res.json({
message: 'pong',
time: format(zonedDate, 'HH:mm:ss:SSS dd/MM/yyyy'),
Expand Down
5 changes: 1 addition & 4 deletions apps/fe/src/app/api/ping/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { toZonedTime } from 'date-fns-tz';
export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
const zonedDate = toZonedTime(
new Date(),
req.body['tz'] || process.env['TZ'] || 'Asia/Ho_Chi_Minh',
);
const zonedDate = toZonedTime(new Date(), process.env?.TZ || 'Asia/Ho_Chi_Minh');
return NextResponse.json({
message: 'pong',
time: format(zonedDate, 'HH:mm:ss:SSS dd/MM/yyyy'),
Expand Down

0 comments on commit 14fed12

Please sign in to comment.