@@ -47,36 +47,35 @@ export const watcher = opts.hot && watch(
4747export const server = Bun . serve ( {
4848 fetch : async ( request , server ) => {
4949 const requestPath = new URL ( request . url ) . pathname ;
50- console . log ( `${ request . method } ${ requestPath } ` ) ;
50+ console . log ( `\n ${ request . method } ${ requestPath } ` ) ;
5151 if ( opts . hot && request . url . endsWith ( HOT_CMD ) ) {
52- console . log ( `Server: Got '${ HOT_CMD } ' request, trying to upgrade...` )
52+ console . log ( `Server: Got '${ HOT_CMD } ' request, trying to upgrade...` ) ;
53+ return server . upgrade ( request ) ;
5354 }
54- else {
55- let filePath = join ( ROOT , requestPath ) ;
56- if ( request . url . endsWith ( "/" ) ) {
57- filePath = `${ filePath } index.html` ;
58- }
59- const file = Bun . file ( filePath ) ;
60- if ( opts . hot && file . type . startsWith ( "text/html" ) ) {
61- return new Response (
62- new HTMLRewriter ( ) . on ( "head" , {
63- element ( head ) {
64- head . append (
65- `<script>
66- const socket = new WebSocket("ws://${ HOSTNAME } :${ PORT } ${ HOT_CMD } ");
67- socket.addEventListener("message", event => window.location.reload());
68- </script>` ,
69- { html : true }
70- ) ;
71- }
72- } ) . transform ( await file . text ( ) ) ,
73- {
74- headers : { "Content-Type" : file . type }
55+ let filePath = join ( ROOT , requestPath ) ;
56+ if ( request . url . endsWith ( "/" ) ) {
57+ filePath = `${ filePath } index.html` ;
58+ }
59+ const file = Bun . file ( filePath ) ;
60+ if ( opts . hot && file . type . startsWith ( "text/html" ) ) {
61+ return new Response (
62+ new HTMLRewriter ( ) . on ( "head" , {
63+ element ( head ) {
64+ head . append (
65+ `<script>
66+ const socket = new WebSocket("ws://${ HOSTNAME } :${ PORT } ${ HOT_CMD } ");
67+ socket.addEventListener("message", event => window.location.reload());
68+ </script>` ,
69+ { html : true }
70+ ) ;
7571 }
76- ) ;
77- }
78- return new Response ( file , { headers :{ "Content-Type" : file . type } } ) ;
72+ } ) . transform ( await file . text ( ) ) ,
73+ {
74+ headers : { "Content-Type" : file . type }
75+ }
76+ ) ;
7977 }
78+ return new Response ( file , { headers :{ "Content-Type" : file . type } } ) ;
8079 } ,
8180 error : ( error ) => {
8281 if ( "ENOENT" === error . code ) {
0 commit comments