initial commit
This commit is contained in:
34
src/dashboardAssets.js
Normal file
34
src/dashboardAssets.js
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { createHttpError } = require("./dashboardUtils");
|
||||
|
||||
const ASSET_MAP = {
|
||||
"/": { file: "index.html", contentType: "text/html; charset=utf-8" },
|
||||
"/dashboard.css": { file: "dashboard.css", contentType: "text/css; charset=utf-8" },
|
||||
"/dashboard.js": {
|
||||
file: "dashboard.js",
|
||||
contentType: "application/javascript; charset=utf-8",
|
||||
},
|
||||
};
|
||||
|
||||
function loadDashboardAsset(assetsDir, requestPath) {
|
||||
const asset = ASSET_MAP[requestPath];
|
||||
if (!asset) return null;
|
||||
|
||||
const filePath = path.join(assetsDir, asset.file);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw createHttpError(500, `대시보드 파일이 없습니다: ${asset.file}`);
|
||||
}
|
||||
|
||||
return {
|
||||
content: fs.readFileSync(filePath),
|
||||
contentType: asset.contentType,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ASSET_MAP,
|
||||
loadDashboardAsset,
|
||||
};
|
||||
Reference in New Issue
Block a user