Last active
September 9, 2026 04:58
-
-
Save PierceLBrooks/b3389a2ca790b05ced89f2e4d5940680 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| var http = require('http'); | |
| var url = require('url'); | |
| var fs = require('fs'); | |
| var mimetypes = { | |
| '.cmft' : 'application/mp4', | |
| '.stpp' : 'application/ttml+xml', | |
| '.ttml' : 'application/ttml+xml', | |
| '.dvb' : 'application/dvbsubs', | |
| '.srt' : 'application/x-subrip', | |
| '.mks' : 'application/x-matroska', | |
| '.ssa' : 'text/x-ssa', | |
| '.ass' : 'text/x-ssa', | |
| '.vtt' : 'text/vtt', | |
| '.wvtt' : 'text/vtt', | |
| '.sub' : 'text/vnd.dvb.subtitle', | |
| '.cmfa' : 'audio/mp4', | |
| '.thx' : 'audio/x-ahx', | |
| '.ahx' : 'audio/x-ahx', | |
| '.xm' : 'audio/xm', | |
| '.mod' : 'audio/mod', | |
| '.mid' : 'audio/midi', | |
| '.midi' : 'audio/midi', | |
| '.mka' : 'audio/x-matroska', | |
| '.oga' : 'audio/ogg', | |
| '.opus' : 'audio/ogg', | |
| '.cda' : 'application/x-cda', | |
| '.ape' : 'audio/x-ape', | |
| '.amr' : 'audio/amr', | |
| '.awb' : 'audio/amr-wb', | |
| '.aac' : 'audio/aac', | |
| '.wav' : 'audio/wav', | |
| '.m4a' : 'audio/mp4', | |
| '.mp3' : 'audio/mpeg', | |
| '.aff' : 'audio/aiff', | |
| '.aif' : 'audio/aiff', | |
| '.aiff' : 'audio/aiff', | |
| '.flac' : 'audio/flac', | |
| '.alac' : 'audio/alac', | |
| '.abc' : 'text/vnd.abc', | |
| '.tga' : 'image/x-targa', | |
| '.webp' : 'image/webp', | |
| '.ico' : 'image/vnd.microsoft.icon', | |
| '.heic' : 'image/heic', | |
| '.heif' : 'image/heif', | |
| '.tiff' : 'image/tiff', | |
| '.tif' : 'image/tiff', | |
| '.jpeg' : 'image/jpeg', | |
| '.jpg' : 'image/jpeg', | |
| '.jxl' : 'image/jxl', | |
| '.jpx' : 'image/jpx', | |
| '.jpm' : 'image/jpm', | |
| '.jp2' : 'image/jp2', | |
| '.png' : 'image/png', | |
| '.apng' : 'image/apng', | |
| '.gif' : 'image/gif', | |
| '.bmp' : 'image/bmp', | |
| '.svg' : 'image/svg+xml', | |
| '.psd' : 'image/vnd.adobe.photoshop', | |
| '.lbm' : 'image/x-ilbm', | |
| '.gv' : 'text/vnd.graphviz', | |
| '.dot' : 'text/vnd.graphviz', | |
| '.xdot' : 'text/vnd.graphviz', | |
| '.proto' : 'application/x+protobuf', | |
| '.ps' : 'application/postscript', | |
| '.marc' : 'application/marc', | |
| '.marcxml' : 'application/marcxml+xml', | |
| '.sql' : 'application/sql', | |
| '.swf' : 'application/x-shockwave-flash', | |
| '.rss' : 'application/rss+xml', | |
| '.opml' : 'text/x-opml', | |
| '.jar' : 'application/java-archive', | |
| '.js' : 'application/javascript', | |
| '.cjs' : 'application/javascript', | |
| '.mjs' : 'application/javascript', | |
| '.wasm' : 'application/wasm', | |
| '.css' : 'text/css', | |
| '.htm' : 'text/html', | |
| '.html' : 'text/html', | |
| '.jsp' : 'text/html', | |
| '.txt' : 'text/plain', | |
| '.md' : 'text/markdown', | |
| '.ics' : 'text/calendar', | |
| '.rtf' : 'application/rtf', | |
| '.pdf' : 'application/pdf', | |
| '.epub' : 'application/epub+zip', | |
| '.plist' : 'application/x-apple-plist+xml', | |
| '.json' : 'application/json', | |
| '.map' : 'application/json', | |
| '.dtd' : 'application/xml-dtd', | |
| '.xml' : 'application/xml', | |
| '.xsd' : 'text/xml', | |
| '.bnf' : 'text/x-bnf', | |
| '.yaml' : 'text/yaml', | |
| '.yml' : 'text/yaml', | |
| '.csv' : 'text/csv', | |
| '.tsv' : 'text/tab-separated-values', | |
| '.yaff' : 'font/x-yaff', | |
| '.pcf' : 'application/x-font-pcf', | |
| '.bdf' : 'application/x-font-bdf', | |
| '.ufo' : 'font/x-ufo', | |
| '.ufoz' : 'font/x-ufo+zip', | |
| '.ttf' : 'application/x-font-ttf', | |
| '.otf' : 'font/otf', | |
| '.woff' : 'font/woff', | |
| '.eot' : 'font/x-eot', | |
| '.gf' : 'application/x-tex-gf', | |
| '.avi' : 'video/x-msvideo', | |
| '.ivf' : 'video/x-ivf', | |
| '.flv' : 'video/flv', | |
| '.jpgv' : 'video/jpeg', | |
| '.mjpeg' : 'video/x-motion-jpeg', | |
| '.mjpg' : 'video/x-motion-jpeg', | |
| '.mj2' : 'video/mj2', | |
| '.mjp2' : 'video/mj2', | |
| '.ogv' : 'video/ogg', | |
| '.webm' : 'video/webm', | |
| '.mpg' : 'video/mpeg', | |
| '.mpeg' : 'video/mpeg', | |
| '.cmfv' : 'video/mp4', | |
| '.mp4' : 'video/mp4', | |
| '.m4v' : 'video/mp4', | |
| '.m4s' : 'video/iso.segment', | |
| '.f4v' : 'video/x-f4v', | |
| '.f4f' : 'video/f4f', | |
| '.f4m' : 'application/f4m+xml', | |
| '.bik' : 'video/vnd.radgametools.bink', | |
| '.xvid' : 'video/xvid', | |
| '.cast' : 'application/x-asciicast', | |
| '.qt' : 'video/quicktime', | |
| '.mov' : 'video/quicktime', | |
| '.mkv' : 'video/x-matroska', | |
| '.mk3d' : 'video/x-matroska-3d', | |
| '.mxf' : 'application/mxf', | |
| '.gxf' : 'application/gxf', | |
| '.ism' : 'application/vnd.ms-sstr+xml', | |
| '.m3u8' : 'application/x-mpegURL', | |
| '.ts' : 'video/MP2T', | |
| '.y4m' : 'video/x-raw-yuv', | |
| '.mpd' : 'application/dash+xml', | |
| '.mpp' : 'application/dash-patch+xml', | |
| '.har' : 'application/har+json', | |
| '.hdf' : 'application/x-hdf', | |
| '.rdf' : 'application/rdf+xml', | |
| '.owl' : 'application/owl+xml', | |
| '.obo' : 'text/obo', | |
| '.ttl' : 'text/turtle', | |
| '.nq' : 'application/n-quads', | |
| '.nt' : 'application/n-triples', | |
| '.n3' : 'text/n3', | |
| '.jsonld' : 'application/ld+json', | |
| '.conllu' : 'text/x-conllu', | |
| '.spdx' : 'application/spdx+json', | |
| '.smil' : 'application/smil+xml', | |
| '.mtl' : 'model/mtl', | |
| '.obj' : 'model/obj', | |
| '.off' : 'text/plain', | |
| '.stl' : 'model/stl', | |
| '.usda' : 'model/vnd.usda', | |
| '.usdz' : 'model/vnd.usdz+zip', | |
| '.glb' : 'model/gltf-binary', | |
| '.gltf' : 'model/gltf+json', | |
| '.fbx' : 'application/fbx', | |
| '.dae' : 'model/vnd.collada+xml', | |
| '.x3d' : 'model/x3d+xml', | |
| '.vrml' : 'model/vrml', | |
| '.wrl' : 'x-world/x-vrml', | |
| '.oog' : 'object/x-oogl', | |
| '.oogl' : 'object/x-oogl', | |
| '.blend' : 'application/x-blender', | |
| '.geojson' : 'application/geo+json', | |
| '.parquet' : 'application/vnd.apache.parquet', | |
| '.wkt' : 'text/plain', | |
| '.3mf' : 'model/3mf', | |
| '.stl' : 'model/stl', | |
| '.brp' : 'model/x-brep', | |
| '.brep' : 'model/x-brep', | |
| '.igs' : 'model/iges', | |
| '.iges' : 'model/iges', | |
| '.stp' : 'model/step', | |
| '.step' : 'model/step', | |
| '.kml' : 'application/vnd.google-earth.kml+xml', | |
| '.kmz' : 'application/vnd.google-earth.kmz', | |
| '.gpkg' : 'application/geopackage+sqlite3', | |
| '.wad' : 'application/x-doom', | |
| '.bsp' : 'application/vnd.valve.source.compiled-map', | |
| '.mpq' : 'application/vnd.blizzard-archive-mopaq', | |
| '.osk' : 'application/x-osu-skin-archive', | |
| '.osz' : 'application/x-osu-beatmap-archive', | |
| '.osu' : 'application/x-osu-beatmap', | |
| '.osr' : 'application/x-osu-replay', | |
| '.sgf' : 'application/x-go-sgf', | |
| '.mjpf' : 'application/vnd.mahjong.mjpf+json', | |
| '.pgn' : 'application/vnd.chess-pgn', | |
| '.emf' : 'application/x-msmetafile', | |
| '.emz' : 'application/x-msmetafile+zip', | |
| '.eml' : 'message/rfc822', | |
| '.msg' : 'application/vnd.ms-outlook', | |
| '.lzh' : 'application/x-lzh-compressed', | |
| '.lha' : 'application/x-lzh-compressed', | |
| '.lzma' : 'application/x-lzma', | |
| '.tar' : 'application/x-tar', | |
| '.br' : 'application/x-brotli', | |
| '.bz' : 'application/x-bzip', | |
| '.bz1' : 'application/x-bzip1', | |
| '.bz2' : 'application/x-bzip2', | |
| '.gz' : 'application/x-gzip', | |
| '.xz' : 'application/x-xz', | |
| '.lz' : 'application/x-lzip', | |
| '.z' : 'application/x-compress', | |
| '.zip' : 'application/zip', | |
| '.rar' : 'application/vnd.rar', | |
| '.zst' : 'application/zstd', | |
| '.7z' : 'application/x-7z-compressed', | |
| '.iff' : 'application/x-iff' | |
| } | |
| function handler(req,resp){ | |
| var pu = url.parse(req.url); | |
| var p = process.cwd() + pu.pathname; | |
| console.log(pu.pathname); | |
| console.log(JSON.stringify(req.headers)); | |
| try{ | |
| var s = fs.statSync(p); | |
| } | |
| catch(e){ | |
| console.log(e.toString()); | |
| resp.writeHead(404,{'Content-type':'text/html'}); | |
| resp.end("<HTML>Not found</HTML>"); | |
| return; | |
| } | |
| if( s.isDirectory() ){ | |
| var pfx = pu.pathname; | |
| if( pfx.length === 0 ) | |
| pfx='/'; | |
| if( pfx[0] !== '/' ) | |
| pfx[0] = '/'; | |
| if( pfx[pfx.length-1] != '/' ) | |
| pfx += '/'; | |
| var L = fs.readdirSync(p); | |
| resp.writeHead(200,{"Content-type":"text/html"}); | |
| resp.write("<!DOCTYPE html>\n"); | |
| resp.write("<html>\n"); | |
| resp.write("<head><meta charset='utf-8'></head>"); | |
| resp.write("<body><ul>"); | |
| for(var i=0;i<L.length;++i){ | |
| try{ | |
| s = fs.statSync(p+L[i]); | |
| if( !s.isDirectory() ){ | |
| s = s.size; | |
| if( s > 1000000000) { | |
| s = ""+(s/1000000000)+" GB"; | |
| } | |
| else{ | |
| if( s > 1000000) { | |
| s = ""+(s/1000000)+" MB"; | |
| } | |
| else{ | |
| if( s > 1000) { | |
| s = ""+(s/1000)+" KB"; | |
| } | |
| else{ | |
| s = ""+s+" B" | |
| } | |
| } | |
| } | |
| resp.write("<li><a href='"+pfx+L[i]+"'>"+L[i]+"</a> ("+s+")</li>\n"); | |
| } | |
| else{ | |
| resp.write("<li><a href='"+pfx+L[i]+"'>"+L[i]+"</a></li>\n"); | |
| } | |
| } | |
| catch(e){ | |
| console.log(e.toString()); | |
| resp.write("<li><a href='"+pfx+L[i]+"'>"+L[i]+"</a></li>\n"); | |
| } | |
| } | |
| resp.end("</ul></body></html>"); | |
| } | |
| else{ | |
| var rs = fs.createReadStream(p); | |
| var i = p.lastIndexOf("."); | |
| var suffix; | |
| if( i === -1 ) | |
| suffix=''; | |
| else | |
| suffix = p.substr(i).toLowerCase(); | |
| var mimetype; | |
| if( mimetypes[suffix] === undefined ) | |
| mimetype='application/octet-stream'; | |
| else | |
| mimetype=mimetypes[suffix]; | |
| resp.writeHead(200,{'Content-type':mimetype,'Content-length':s.size}); | |
| rs.pipe(resp); | |
| } | |
| } | |
| var server = http.createServer(handler); | |
| server.listen(8081,'127.0.0.1'); | |
| console.log("Listening on port 8081"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment