2023-02-12 07:40:49 +00:00
import "dotenv/config" ;
2022-07-08 18:17:56 +00:00
import express from "express" ;
2023-04-29 11:40:08 +00:00
2023-05-21 19:13:05 +00:00
import { Bright , Green , Red } from "./modules/sub/consoleText.js" ;
import { getCurrentBranch , shortCommit } from "./modules/sub/currentCommit.js" ;
import { loadLoc } from "./localization/manager.js" ;
2022-07-08 18:17:56 +00:00
2023-03-09 18:41:17 +00:00
import path from 'path' ;
import { fileURLToPath } from 'url' ;
2022-07-08 18:17:56 +00:00
2023-05-21 19:13:05 +00:00
import { runWeb } from "./core/web.js" ;
import { runAPI } from "./core/api.js" ;
2023-04-08 10:58:44 +00:00
2023-05-21 19:13:05 +00:00
const app = express ( ) ;
2022-07-10 14:04:03 +00:00
2023-05-21 19:13:05 +00:00
const gitCommit = shortCommit ( ) ;
const gitBranch = getCurrentBranch ( ) ;
2022-07-08 18:17:56 +00:00
2023-05-21 19:13:05 +00:00
const _ _filename = fileURLToPath ( import . meta . url ) ;
2023-06-27 13:56:15 +00:00
const _ _dirname = path . dirname ( _ _filename ) . slice ( 0 , - 4 ) ;
2023-02-12 07:40:49 +00:00
2023-05-21 19:13:05 +00:00
app . disable ( 'x-powered-by' ) ;
2023-02-12 07:40:49 +00:00
2023-06-27 13:56:15 +00:00
await loadLoc ( ) ;
2023-02-12 07:40:49 +00:00
2023-07-02 01:02:15 +00:00
const apiMode = process . env . apiURL && process . env . apiPort && ! ( ( process . env . webURL && process . env . webPort ) || ( process . env . selfURL && process . env . port ) )
const webMode = process . env . webURL && process . env . webPort && ! ( ( process . env . apiURL && process . env . apiPort ) || ( process . env . selfURL && process . env . port ) )
if ( apiMode ) {
2023-06-27 13:56:15 +00:00
runAPI ( express , app , gitCommit , gitBranch , _ _dirname ) ;
2023-07-02 01:02:15 +00:00
} else if ( webMode ) {
2023-05-21 19:13:05 +00:00
await runWeb ( express , app , gitCommit , gitBranch , _ _dirname ) ;
2022-07-08 18:17:56 +00:00
} else {
2023-06-27 13:56:15 +00:00
console . log ( Red ( ` cobalt wasn't configured yet or configuration is invalid. \n ` ) + Bright ( ` please run the setup script to fix this: ` ) + Green ( ` npm run setup ` ) ) ;
2022-08-01 15:48:37 +00:00
}