diff --git a/apps/be/src/app/app.service.ts b/apps/be/src/app/app.service.ts index d8710e8..45e0341 100644 --- a/apps/be/src/app/app.service.ts +++ b/apps/be/src/app/app.service.ts @@ -1,13 +1,15 @@ import { Response } from 'express'; import { Injectable } from '@nestjs/common'; -import { format } from 'date-fns/format'; +import { toZonedTime, format } from 'date-fns-tz'; @Injectable() export class AppService { getPing(res: Response) { - res.header('Cache-Control', 'no-store, max-age=0, must-revalidate') - .header('Content-Type', 'text/plain') - .send(`pong ${format(new Date(), 'HH:mm:ss:SSS dd/MM/yyyy')}`); + 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'), + }); return; } } diff --git a/apps/fe/src/app/api/ping/route.ts b/apps/fe/src/app/api/ping/route.ts index 3a9121a..2e8941f 100644 --- a/apps/fe/src/app/api/ping/route.ts +++ b/apps/fe/src/app/api/ping/route.ts @@ -1,11 +1,12 @@ -import { NextRequest, NextResponse } from 'next/server'; -import { format } from 'date-fns/format'; +import { type NextRequest, NextResponse } from 'next/server'; +import { toZonedTime, format } from 'date-fns-tz'; -export async function GET(request: NextRequest) { - return new NextResponse(`pong ${format(new Date(), 'HH:mm:ss:SSS dd/MM/yyyy')}`, { - headers: { - 'Cache-Control': 'no-store, max-age=0, must-revalidate', - 'Content-Type': 'text/plain', - }, +export const dynamic = 'force-dynamic'; + +export async function GET(_req: NextRequest) { + 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'), }); } diff --git a/package.json b/package.json index 5c51721..2be69f4 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "cronstrue": "^2.50.0", "cross-env": "^7.0.3", "date-fns": "^3.6.0", + "date-fns-tz": "^3.1.3", "google-auth-library": "^9.11.0", "helmet": "^7.1.0", "ioredis": "^5.4.1", diff --git a/yarn.lock b/yarn.lock index ddeacfa..9db0534 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5081,6 +5081,7 @@ __metadata: cross-env: "npm:^7.0.3" cypress: "npm:^13.8.0" date-fns: "npm:^3.6.0" + date-fns-tz: "npm:^3.1.3" eslint: "npm:~8.57.0" eslint-config-next: "npm:14.2.3" eslint-config-prettier: "npm:^9.1.0" @@ -9119,6 +9120,15 @@ __metadata: languageName: node linkType: hard +"date-fns-tz@npm:^3.1.3": + version: 3.1.3 + resolution: "date-fns-tz@npm:3.1.3" + peerDependencies: + date-fns: ^3.0.0 + checksum: 10c0/dcedf178a96632a798966cf5a881441aefc451cc308336a98919e49c2df8eff7a302d19b9d3903c50838dd0912533f862f0bfb9429e8c28c1c3ce5da19ccb64e + languageName: node + linkType: hard + "date-fns@npm:^3.6.0": version: 3.6.0 resolution: "date-fns@npm:3.6.0"