core/dashboard/server.js
Tiago Yamamoto a52bd4519d refactor: optimize Dockerfiles and documentation for core services
- Use Google Distroless images for all services (Go & Node.js).
- Standardize documentation with [PROJECT-NAME].md.
- Add .dockerignore and .gitignore to all projects.
- Remove docker-compose.yml in favor of docker run instructions.
- Fix Go version and dependency issues in observability, repo-integrations, and security-governance.
- Add Podman support (fully qualified image names).
- Update Dashboard to use Node.js static server for Distroless compatibility.
2025-12-30 13:22:34 -03:00

47 lines
1.4 KiB
JavaScript

const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = process.env.PORT || 3000;
const PUBLIC_DIR = path.join(__dirname, 'dist');
const getContentType = (filePath) => {
const ext = path.extname(filePath).toLowerCase();
const types = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
};
return types[ext] || 'application/octet-stream';
};
const server = http.createServer((req, res) => {
let filePath = path.join(PUBLIC_DIR, req.url === '/' ? 'index.html' : req.url);
fs.stat(filePath, (err, stats) => {
if (err || !stats.isFile()) {
// SPA Fallback: serve index.html for unknown paths
filePath = path.join(PUBLIC_DIR, 'index.html');
}
fs.readFile(filePath, (err, content) => {
if (err) {
res.writeHead(500);
res.end('Server Error');
} else {
res.writeHead(200, { 'Content-Type': getContentType(filePath) });
res.end(content, 'utf-8');
}
});
});
});
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});