@whykusanagi/corrupted-theme 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Simple Static File Server
4
+ * Serves static files for whykusanagi.xyz portfolio
5
+ */
6
+
7
+ import http from 'http';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+ const ROOT_DIR = path.join(__dirname, '..');
15
+
16
+ const PORT = process.env.STATIC_PORT || 8000;
17
+ const HOST = process.env.HOST || '0.0.0.0';
18
+
19
+ // MIME types
20
+ const MIME_TYPES = {
21
+ '.html': 'text/html',
22
+ '.css': 'text/css',
23
+ '.js': 'application/javascript',
24
+ '.json': 'application/json',
25
+ '.png': 'image/png',
26
+ '.jpg': 'image/jpeg',
27
+ '.jpeg': 'image/jpeg',
28
+ '.gif': 'image/gif',
29
+ '.svg': 'image/svg+xml',
30
+ '.webm': 'video/webm',
31
+ '.mp4': 'video/mp4',
32
+ '.webp': 'image/webp',
33
+ '.ico': 'image/x-icon',
34
+ '.txt': 'text/plain'
35
+ };
36
+
37
+ function getMimeType(filePath) {
38
+ const ext = path.extname(filePath).toLowerCase();
39
+ return MIME_TYPES[ext] || 'application/octet-stream';
40
+ }
41
+
42
+ function serveFile(filePath, res) {
43
+ const fullPath = path.join(ROOT_DIR, filePath);
44
+
45
+ // Security: prevent directory traversal
46
+ if (!fullPath.startsWith(ROOT_DIR)) {
47
+ res.writeHead(403);
48
+ res.end('Forbidden');
49
+ return;
50
+ }
51
+
52
+ fs.stat(fullPath, (err, stats) => {
53
+ if (err || !stats.isFile()) {
54
+ // Try index.html for directories
55
+ if (filePath.endsWith('/') || filePath === '') {
56
+ const indexPath = path.join(fullPath, 'index.html');
57
+ fs.stat(indexPath, (err2, stats2) => {
58
+ if (err2 || !stats2.isFile()) {
59
+ res.writeHead(404);
60
+ res.end('Not Found');
61
+ } else {
62
+ serveFileContent(indexPath, res);
63
+ }
64
+ });
65
+ } else {
66
+ res.writeHead(404);
67
+ res.end('Not Found');
68
+ }
69
+ return;
70
+ }
71
+
72
+ serveFileContent(fullPath, res);
73
+ });
74
+ }
75
+
76
+ function serveFileContent(filePath, res) {
77
+ const mimeType = getMimeType(filePath);
78
+
79
+ fs.readFile(filePath, (err, data) => {
80
+ if (err) {
81
+ res.writeHead(500);
82
+ res.end('Internal Server Error');
83
+ return;
84
+ }
85
+
86
+ res.writeHead(200, {
87
+ 'Content-Type': mimeType,
88
+ 'Cache-Control': 'public, max-age=3600'
89
+ });
90
+ res.end(data);
91
+ });
92
+ }
93
+
94
+ const server = http.createServer((req, res) => {
95
+ // Parse URL
96
+ const url = new URL(req.url, `http://${req.headers.host}`);
97
+ let filePath = url.pathname;
98
+
99
+ // Default to showcase-complete.html for root (comprehensive component showcase)
100
+ if (filePath === '/') {
101
+ filePath = '/examples/showcase-complete.html';
102
+ }
103
+
104
+ // Remove leading slash
105
+ filePath = filePath.substring(1);
106
+
107
+ serveFile(filePath, res);
108
+ });
109
+
110
+ server.listen(PORT, HOST, () => {
111
+ console.log(`📁 Static file server running on http://${HOST}:${PORT}`);
112
+ });
113
+