@@ -24,20 +24,20 @@ export interface ServeOptions {
2424}
2525
2626export async function serve ( options : ServeOptions = { } ) {
27- const port = options . port !== undefined ? options . port : 4173
28- const site = await resolveConfig ( options . root , 'serve' , 'production' )
29- const base = trimChar ( options ?. base ?? site ?. site ?. base ?? '' , '/' )
27+ const port = options . port ?? 4173
28+ const config = await resolveConfig ( options . root , 'serve' , 'production' )
29+ const base = trimChar ( options ?. base ?? config ?. site ?. base ?? '' , '/' )
3030
3131 const notAnAsset = ( pathname : string ) => ! pathname . includes ( '/assets/' )
32- const notFound = fs . readFileSync ( path . resolve ( site . outDir , './404.html' ) )
32+ const notFound = fs . readFileSync ( path . resolve ( config . outDir , './404.html' ) )
3333 const onNoMatch : IOptions [ 'onNoMatch' ] = ( req , res ) => {
3434 res . statusCode = 404
3535 if ( notAnAsset ( req . path ) ) res . write ( notFound . toString ( ) )
3636 res . end ( )
3737 }
3838
3939 const compress = compression ( ) as RequestHandler
40- const serve = sirv ( site . outDir , {
40+ const serve = sirv ( config . outDir , {
4141 etag : true ,
4242 maxAge : 31536000 ,
4343 immutable : true ,
@@ -54,15 +54,15 @@ export async function serve(options: ServeOptions = {}) {
5454 return polka ( { onNoMatch } )
5555 . use ( base , compress , serve )
5656 . listen ( port , ( ) => {
57- site . logger . info (
57+ config . logger . info (
5858 `Built site served at http://localhost:${ port } /${ base } /`
5959 )
6060 } )
6161 } else {
6262 return polka ( { onNoMatch } )
6363 . use ( compress , serve )
6464 . listen ( port , ( ) => {
65- site . logger . info ( `Built site served at http://localhost:${ port } /` )
65+ config . logger . info ( `Built site served at http://localhost:${ port } /` )
6666 } )
6767 }
6868}
0 commit comments