1- import { createRequestHandler } from "@react-router/express" ;
2- import { createCommand , flag } from "commandstruct" ;
3- import compression from "compression" ;
4- import express from "express" ;
5- import morgan from "morgan" ;
6- import os from "node:os" ;
7- import path from "node:path" ;
8- import url from "node:url" ;
9- import { type ServerBuild } from "react-router" ;
10- import type { Database } from "~/core/database" ;
1+ import { createRequestHandler } from "@react-router/express"
2+ import { createCommand , flag } from "commandstruct"
3+ import compression from "compression"
4+ import express from "express"
5+ import morgan from "morgan"
6+ import os from "node:os"
7+ import path from "node:path"
8+ import url from "node:url"
9+ import { type ServerBuild } from "react-router"
10+ import type { Database } from "~/core/database"
1111
1212export const studioCmd = createCommand ( "studio" )
1313 . use < { database : Database } > ( )
1414 . flags ( {
1515 port : flag ( "web server port" ) . char ( "p" ) . optionalParam ( "number" , 6543 ) ,
1616 } )
1717 . action ( async ( { flags } ) => {
18- let buildPath = import . meta. dirname ;
18+ let buildPath = import . meta. dirname
1919 if ( buildPath . endsWith ( "dist" ) ) {
20- buildPath = path . join ( buildPath , "ui/server/index.js" ) ;
20+ buildPath = path . join ( buildPath , "ui/server/index.js" )
2121 } else {
2222 // during development the ui dir different
23- buildPath = path . join ( buildPath , "../dist/ui/server/index.js" ) ;
23+ buildPath = path . join ( buildPath , "../dist/ui/server/index.js" )
2424 }
2525
2626 const build : ServerBuild | null = await import (
2727 url . pathToFileURL ( buildPath ) . href
28- ) . catch ( ( ) => null ) ;
28+ ) . catch ( ( ) => null )
2929 if ( ! build ) {
3030 return console . error (
31- `[monarch-studio] err: missing build output at ${ buildPath } `
32- ) ;
31+ `[monarch-studio] err: missing build output at ${ buildPath } ` ,
32+ )
3333 }
3434
35- runServer ( build , flags . port ) ;
36- } ) ;
35+ runServer ( build , flags . port )
36+ } )
3737
3838function runServer ( build : ServerBuild , port : number ) {
3939 function onListen ( ) {
@@ -42,42 +42,42 @@ function runServer(build: ServerBuild, port: number) {
4242 Object . values ( os . networkInterfaces ( ) )
4343 . flat ( )
4444 . find ( ( ip ) => String ( ip ?. family ) . includes ( "4" ) && ! ip ?. internal )
45- ?. address ;
45+ ?. address
4646
4747 if ( ! address ) {
48- console . log ( `[monarch-studio] http://localhost:${ port } ` ) ;
48+ console . log ( `[monarch-studio] http://localhost:${ port } ` )
4949 } else {
5050 console . log (
51- `[monarch-studio] http://localhost:${ port } (http://${ address } :${ port } )`
52- ) ;
51+ `[monarch-studio] http://localhost:${ port } (http://${ address } :${ port } )` ,
52+ )
5353 }
5454 }
5555
56- const app = express ( ) ;
57- app . disable ( "x-powered-by" ) ;
58- app . use ( compression ( ) ) ;
56+ const app = express ( )
57+ app . disable ( "x-powered-by" )
58+ app . use ( compression ( ) )
5959 app . use (
6060 path . posix . join ( build . publicPath , "assets" ) ,
6161 express . static ( path . join ( build . assetsBuildDirectory , "assets" ) , {
6262 immutable : true ,
6363 maxAge : "1y" ,
64- } )
65- ) ;
64+ } ) ,
65+ )
6666 app . use (
6767 build . publicPath ,
6868 express . static ( build . assetsBuildDirectory , {
6969 immutable : true ,
7070 maxAge : "1y" ,
71- } )
72- ) ;
73- app . use ( express . static ( "public" , { maxAge : "1h" } ) ) ;
74- app . use ( morgan ( "tiny" ) ) ;
75- app . all ( "*" , createRequestHandler ( { build, mode : "production" } ) ) ;
71+ } ) ,
72+ )
73+ app . use ( express . static ( "public" , { maxAge : "1h" } ) )
74+ app . use ( morgan ( "tiny" ) )
75+ app . all ( "*" , createRequestHandler ( { build, mode : "production" } ) )
7676
7777 const server = process . env . HOST
7878 ? app . listen ( port , process . env . HOST , onListen )
79- : app . listen ( port , onListen ) ;
79+ : app . listen ( port , onListen )
8080
81- process . once ( "SIGTERM" , ( ) => server ?. close ( console . error ) ) ;
82- process . once ( "SIGINT" , ( ) => server ?. close ( console . error ) ) ;
81+ process . once ( "SIGTERM" , ( ) => server ?. close ( console . error ) )
82+ process . once ( "SIGINT" , ( ) => server ?. close ( console . error ) )
8383}
0 commit comments