@ -12,22 +12,26 @@ import logger from './logger.mjs';
import events from './emitter.mjs' ;
import events from './emitter.mjs' ;
const pubDir = path . join ( __ dirname , '..' , 'public' ) ;
const pubDir = path . join ( __ dirname , '..' , 'public' ) ;
const distDir = path . join ( __ dirname , '..' , 'dist' ) ;
export default function createServer ( port , { key , cert } ) {
export default function createServer ( base , port , { key , cert } ) {
events . emit ( 'debug' , ` key: ${ key } , cert: ${ cert } , port: ${ port } ` ) ;
base = base . replace ( /\/*$/ , "" ) ;
events . emit ( 'debug' , ` key: ${ key } , cert: ${ cert } , port: ${ port } , base: ${ base } ` ) ;
const app = express ( ) ;
const app = express ( ) ;
const wetty = ( req , res ) => res . sendFile ( path . join ( pubDir , 'index.html' ) ) ;
const html = ( req , res ) => res . sendFile ( path . join ( pubDir , 'index.html' ) ) ;
const css = ( req , res ) => res . sendFile ( path . join ( distDir , 'main.css' ) ) ;
const js = ( req , res ) => res . sendFile ( path . join ( distDir , 'main.js' ) ) ;
app
app
. use ( morgan ( 'combined' , { stream : logger . stream } ) )
. use ( morgan ( 'combined' , { stream : logger . stream } ) )
. use ( helmet ( ) )
. use ( helmet ( ) )
. use ( compression ( ) )
. use ( compression ( ) )
. use ( favicon ( path . join ( pubDir , 'favicon.ico' ) ) )
. use ( favicon ( path . join ( pubDir , 'favicon.ico' ) ) )
. get ( '/wetty/ssh/:user' , wetty )
. get ( ` ${ base } / ` , html )
. get ( '/wetty/' , wetty )
. get ( ` ${ base } /main.css ` , css )
. use ( '/wetty' , express . static ( path . join ( __ dirname , '..' , 'dist' ) ) )
. get ( ` ${ base } /main.js ` , js )
. get ( '/ssh/:user' , wetty )
. get ( ` ${ base } /ssh/main.css ` , css )
. get ( '/' , wetty )
. get ( ` ${ base } /ssh/main.js ` , js )
. use ( '/' , express . static ( path . join ( __ dirname , '..' , 'dist' ) ) ) ;
. get ( ` ${ base } /ssh/:user ` , html )
return socket (
return socket (
! isUndefined ( key ) && ! isUndefined ( cert )
! isUndefined ( key ) && ! isUndefined ( cert )
@ -37,6 +41,6 @@ export default function createServer(port, { key, cert }) {
: http . createServer ( app ) . listen ( port , ( ) => {
: http . createServer ( app ) . listen ( port , ( ) => {
events . server ( port , 'http' ) ;
events . server ( port , 'http' ) ;
} ) ,
} ) ,
{ path : '/wetty/socket.io' }
{ path : ` ${ base } /socket.io ` }
) ;
) ;
}
}