Skip to content

Commit

Permalink
feat: ⚡ update ping request to response json
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Jun 24, 2024
1 parent 12e1f81 commit 795ec2b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 6 additions & 4 deletions apps/be/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 9 additions & 8 deletions apps/fe/src/app/api/ping/route.ts
Original file line number Diff line number Diff line change
@@ -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'),
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 795ec2b

Please sign in to comment.