added server time
This commit is contained in:
@@ -59,6 +59,22 @@ async function startServer() {
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
app.use(express.json());
|
||||
// --- Public server time endpoints (no auth, no cache) ---
|
||||
const timeHandler = (req, res) => {
|
||||
const now = new Date();
|
||||
const ymdKL = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Kuala_Lumpur',
|
||||
year: 'numeric', month: '2-digit', day: '2-digit'
|
||||
}).format(now); // "YYYY-MM-DD"
|
||||
|
||||
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
||||
res.set('Pragma', 'no-cache');
|
||||
res.set('Expires', '0');
|
||||
|
||||
res.json({ nowIso: now.toISOString(), tz: 'Asia/Kuala_Lumpur', ymdKL });
|
||||
};
|
||||
app.get('/time', timeHandler); // public path
|
||||
app.get('/api/time', timeHandler); // also under /api
|
||||
|
||||
app.use('/api/managers', managerRoutes(db));
|
||||
app.use('/api', workerRoutes(db));
|
||||
|
||||
Reference in New Issue
Block a user