@@ -89,38 +89,39 @@ export class Server {
89
89
req . status ( status ) . send ( '' )
90
90
}
91
91
return
92
- } else if ( reHashJs . test ( pathname ) && [ 'main' , 'main.bundle' ] . includes ( util . trimPrefix ( pathname , '/_aleph/' ) . replace ( reHashJs , '' ) ) ) {
93
- req . send ( app . getMainJS ( pathname . startsWith ( '/_aleph/main.bundle' ) ) , 'application/javascript; charset=utf-8' )
92
+ }
93
+
94
+ if ( pathname . startsWith ( '/_aleph/main' ) && [ 'main' , 'main.bundle' ] . includes ( util . trimPrefix ( pathname , '/_aleph/' ) . replace ( reHashJs , '' ) ) ) {
95
+ req . send ( app . getMainJS ( pathname . includes ( '.bundle.' ) ) , 'application/javascript; charset=utf-8' )
94
96
return
95
- } else {
96
- const filePath = path . join ( app . buildDir , util . trimPrefix ( pathname , '/_aleph/' ) )
97
- if ( existsFileSync ( filePath ) ) {
98
- const info = Deno . lstatSync ( filePath )
99
- const lastModified = info . mtime ?. toUTCString ( ) ?? new Date ( ) . toUTCString ( )
100
- if ( lastModified === r . headers . get ( 'If-Modified-Since' ) ) {
101
- req . status ( 304 ) . send ( '' )
102
- return
103
- }
97
+ }
104
98
105
- let content = await Deno . readTextFile ( filePath )
99
+ const filePath = path . join ( app . buildDir , util . trimPrefix ( pathname , '/_aleph/' ) )
100
+ if ( existsFileSync ( filePath ) ) {
101
+ const info = Deno . lstatSync ( filePath )
102
+ const lastModified = info . mtime ?. toUTCString ( ) ?? new Date ( ) . toUTCString ( )
103
+ if ( lastModified === r . headers . get ( 'If-Modified-Since' ) ) {
104
+ req . status ( 304 ) . send ( '' )
105
+ return
106
+ }
106
107
107
- if ( reHashJs . test ( filePath ) ) {
108
- const metaFile = filePath . replace ( reHashJs , '' ) + '.meta.json'
109
- if ( existsFileSync ( metaFile ) ) {
110
- try {
111
- const { url } = JSON . parse ( await Deno . readTextFile ( metaFile ) )
112
- const mod = app . getModule ( url )
113
- if ( mod && app . isHMRable ( mod . url ) ) {
114
- content = app . injectHMRCode ( mod , content )
115
- }
116
- } catch ( e ) { }
117
- }
108
+ let content = await Deno . readTextFile ( filePath )
109
+ if ( reHashJs . test ( filePath ) ) {
110
+ const metaFile = filePath . replace ( reHashJs , '' ) + '.meta.json'
111
+ if ( existsFileSync ( metaFile ) ) {
112
+ try {
113
+ const { url } = JSON . parse ( await Deno . readTextFile ( metaFile ) )
114
+ const mod = app . getModule ( url )
115
+ if ( mod && app . isHMRable ( mod . url ) ) {
116
+ content = app . injectHMRCode ( mod , content )
117
+ }
118
+ } catch ( e ) { }
118
119
}
119
-
120
- req . setHeader ( 'Last-Modified' , lastModified )
121
- req . send ( content , getContentType ( filePath ) )
122
- return
123
120
}
121
+
122
+ req . setHeader ( 'Last-Modified' , lastModified )
123
+ req . send ( content , getContentType ( filePath ) )
124
+ return
124
125
}
125
126
126
127
req . status ( 404 ) . send ( 'file not found' )
@@ -206,7 +207,7 @@ export async function serve({ app, port, hostname, certFile, keyFile }: ServeOpt
206
207
} else {
207
208
s = stdServe ( { port, hostname } )
208
209
}
209
- log . info ( `Aleph server ready on http://${ hostname || 'localhost' } :${ port } ${ app . config . baseUrl } ` )
210
+ log . info ( `Server ready on http://${ hostname || 'localhost' } :${ port } ${ app . config . baseUrl } ` )
210
211
for await ( const r of s ) {
211
212
server . handle ( r )
212
213
}
0 commit comments