@@ -63,6 +63,22 @@ export async function start(appDir: string, port: number, isDev = false, reload
63
63
continue
64
64
}
65
65
66
+ // serve public files
67
+ const filePath = path . join ( project . appRoot , 'public' , decodeURI ( pathname ) )
68
+ if ( existsFileSync ( filePath ) ) {
69
+ const info = Deno . lstatSync ( filePath )
70
+ const lastModified = info . mtime ?. toUTCString ( ) ?? new Date ( ) . toUTCString ( )
71
+ if ( lastModified === req . headers . get ( 'If-Modified-Since' ) ) {
72
+ resp . status ( 304 ) . send ( '' )
73
+ continue
74
+ }
75
+
76
+ const body = Deno . readFileSync ( filePath )
77
+ resp . setHeader ( 'Last-Modified' , lastModified )
78
+ resp . send ( body , getContentType ( filePath ) )
79
+ continue
80
+ }
81
+
66
82
// serve APIs
67
83
if ( pathname . startsWith ( '/api/' ) ) {
68
84
project . callAPI ( req , { pathname, search : url . search } )
@@ -113,21 +129,6 @@ export async function start(appDir: string, port: number, isDev = false, reload
113
129
}
114
130
}
115
131
116
- // serve public files
117
- const filePath = path . join ( project . appRoot , 'public' , pathname )
118
- if ( existsFileSync ( filePath ) ) {
119
- const info = await Deno . lstat ( filePath )
120
- if ( info . mtime ?. toUTCString ( ) === req . headers . get ( 'If-Modified-Since' ) ) {
121
- resp . status ( 304 ) . send ( '' )
122
- continue
123
- }
124
-
125
- const body = await Deno . readFile ( filePath )
126
- resp . setHeader ( 'Last-Modified' , info . mtime ! . toUTCString ( ) )
127
- resp . send ( body , getContentType ( filePath ) )
128
- continue
129
- }
130
-
131
132
// ssr
132
133
const [ status , html ] = await project . getPageHtml ( { pathname, search : url . search } )
133
134
resp . status ( status ) . send ( html , 'text/html; charset=utf-8' )
0 commit comments