2023-06-22 19:36:52 +05:00
const https = require ( "https" ) ;
const http = require ( "http" ) ;
const { Server : SocketServer } = require ( "socket.io" ) ;
2023-06-19 12:35:11 +05:00
module . exports = ( app , config , themeConfig , modules ) => {
2023-06-22 19:36:52 +05:00
if ( config . noCreateServer ) return { io : null , server : null } ;
let server ;
if ( ! config . SSL ) config . SSL = { } ;
if ( config . SSL . enabled ) {
if ( ! config . SSL . key || ! config . SSL . cert ) console . log ( ` ${ "discord-dashboard issue:" . red } The SSL preference for Dashboard is selected (config.SSL.enabled), but config does not include key or cert (config.SSL.key, config.SSL.cert). ` ) ;
const options = {
key : config . SSL . key || "" ,
cert : config . SSL . cert || "" ,
} ;
try {
server = https . createServer ( options , app ) ;
} catch ( e ) {
2023-06-27 00:43:31 +05:00
console . log ( ` ${ "discord-dashboard issue:" . red } There's a problem while creating server, check if the port specified is already on use. \n ${ e } ` ) ;
2023-06-22 19:36:52 +05:00
}
} else {
server = http . createServer ( app ) ;
}
let pport = "" ;
if ( config . port != 80 && config . port != 443 ) pport = ` : ${ config . port } ` ;
console . log ( ` DBD Dashboard running on ${ ` ${ ( config . domain || "domain.com" ) + pport } ` . blue } ! ` ) ;
const io = new SocketServer ( server , {
cors : {
origin : "*" ,
} ,
} ) ;
modules . forEach ( ( module ) => {
module . server ( {
io : io ,
server : server ,
config : config ,
themeConfig : themeConfig ,
} ) ;
} ) ;
server . listen ( config . port ) ;
return { server , io } ;
} ;