-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ⚡ update ping request to response json
- Loading branch information
1 parent
12e1f81
commit 795ec2b
Showing
4 changed files
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters