feat: add favicon; support for binary data

This commit is contained in:
2025-03-24 00:01:48 -07:00
parent 1160f43820
commit f0237eb488
3 changed files with 10 additions and 4 deletions

View File

@@ -1003,8 +1003,6 @@ const server = http.createServer( ( request, response ) =>
{ {
if ( !err ) if ( !err )
{ {
const html = data.toString();
/* /*
This allows us to serve all files locally: css, js, etc. This allows us to serve all files locally: css, js, etc.
the file loaded is dependent on what comes to the right of the period. the file loaded is dependent on what comes to the right of the period.
@@ -1022,10 +1020,17 @@ const server = http.createServer( ( request, response ) =>
'.css' : 'text/css', '.css' : 'text/css',
'.gz' : 'application/gzip', '.gz' : 'application/gzip',
'.js' : 'text/javascript' '.js' : 'text/javascript'
}[loadAsset.substr( fileExt )]; }[loadAsset.substring( fileExt )];
/*
ejs is only for templates; if we want to load an binary data (like images); we must use fs.readFile
*/
if ( fileMime !== 'text/html' )
data = fs.readFileSync( './www/' + loadAsset );
response.setHeader( 'Content-type', fileMime ); response.setHeader( 'Content-type', fileMime );
response.end( html ); response.end( data );
Log.debug( `www`, chalk.green( ` [LOAD] ` ), chalk.white( `` ), chalk.grey( `asset:${ loadAsset } mime:${ fileMime }` ) ); Log.debug( `www`, chalk.green( ` [LOAD] ` ), chalk.white( `` ), chalk.grey( `asset:${ loadAsset } mime:${ fileMime }` ) );
} }

BIN
tvapp2/www/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@@ -7,6 +7,7 @@
<meta name="robots" content="noindex, nofollow"> <meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="css/tvapp2.min.css"> <link rel="stylesheet" href="css/tvapp2.min.css">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head> </head>
<body> <body>
<div class="header"> <div class="header">