This commit is contained in:
2025-12-15 12:28:00 -06:00
parent bdc709ec2a
commit cf1ffac9ee
14 changed files with 3181 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
// Simple Bun server for development
const server = Bun.serve({
port: 3075,
async fetch(request) {
const url = new URL(request.url);
let pathname = url.pathname;
// Default to index.html for root
if (pathname === '/') {
pathname = '/index.html';
}
// Try to serve the file
const file = Bun.file('.' + pathname);
// If file doesn't exist, try with .html extension
if (!(await file.exists())) {
const htmlFile = Bun.file('.' + pathname + '.html');
if (await htmlFile.exists()) {
return new Response(htmlFile, {
headers: {
'Content-Type': getContentType(pathname + '.html'),
},
});
}
}
// Serve the file if it exists
if (await file.exists()) {
return new Response(file, {
headers: {
'Content-Type': getContentType(pathname),
},
});
}
// 404 for not found
return new Response('Not Found', { status: 404 });
},
});
function getContentType(pathname) {
const ext = pathname.split('.').pop()?.toLowerCase();
const types = {
'html': 'text/html',
'css': 'text/css',
'js': 'application/javascript',
'json': 'application/json',
'png': 'image/png',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'svg': 'image/svg+xml',
'ico': 'image/x-icon',
};
return types[ext] || 'text/plain';
}
console.log(`🚀 Server running at http://localhost:${server.port}`);
console.log(`📁 Serving files from: ${process.cwd()}`);