feat: inisialisasi server Express dengan Node.js, TypeScript, dan middleware keamanan

This commit is contained in:
Rafi Athallah
2026-05-22 14:20:09 +07:00
parent db4f4861ca
commit 15efd81134
9 changed files with 2578 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import { Router, Request, Response, NextFunction } from 'express';
const router = Router();
/**
* @route GET /api/health
* @desc Endpoint untuk memeriksa kesehatan/status server
* @access Public
*/
router.get('/health', (_req: Request, res: Response) => {
res.status(200).json({
status: 'OK',
message: 'Server is running smoothly',
timestamp: new Date().toISOString(),
});
});
/**
* @route GET /api/error-test
* @desc Mensimulasikan error server internal untuk memverifikasi middleware penanganan error global
* @access Public
*/
router.get('/error-test', (_req: Request, _res: Response, next: NextFunction) => {
try {
throw new Error('This is a test error to verify our custom global error handler!');
} catch (error) {
next(error);
}
});
export default router;