2025-04-27 23:29:32 +07:00

57 lines
2.0 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.router = void 0;
const express_1 = require("express");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
exports.router = (0, express_1.Router)();
const htmlIndex = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>404 - Not Found</title>
<style>
body {
font-family: "Arial", sans-serif;
background-color: #f4f4f4;
text-align: center;
padding: 50px;
}
h1 {
color: #333;
}
p {
color: #666;
}
</style>
</head>
<body>
<h1>404 - Not Found</h1>
<p>Maaf, Endpoint yang Anda cari tidak ditemukan.</p>
</body>
</html>
`;
exports.router.use("*", (req, res) => {
if (fs_1.default.existsSync(path_1.default.join(__dirname, "./views")) === true) {
if (fs_1.default.existsSync(path_1.default.join(__dirname, "./views/404.html")) === true) {
res.sendFile(path_1.default.join(__dirname, "./views", "404.html"));
}
else {
fs_1.default.writeFileSync(path_1.default.join(__dirname, "./views/404.html"), htmlIndex);
res.sendFile(path_1.default.join(__dirname, "./views", "404.html"));
}
}
else {
fs_1.default.mkdirSync(path_1.default.join(__dirname, "./views"));
fs_1.default.writeFileSync(path_1.default.join(__dirname, "./views/404.html"), htmlIndex);
res.sendFile(path_1.default.join(__dirname, "./views", "404.html"));
}
});