api & web: ports in env are no longer strictly required

This commit is contained in:
wukko 2023-12-02 22:01:58 +06:00
parent 3e8c059a3a
commit afab7f94a7
4 changed files with 13 additions and 11 deletions

View file

@ -17,7 +17,6 @@ services:
#- 127.0.0.1:9000:9000 #- 127.0.0.1:9000:9000
environment: environment:
- apiPort=9000
# replace apiURL with your instance's target url in same format # replace apiURL with your instance's target url in same format
- apiURL=https://co.wuk.sh/ - apiURL=https://co.wuk.sh/
# replace apiName with your instance's distinctive name # replace apiName with your instance's distinctive name
@ -48,7 +47,6 @@ services:
#- 127.0.0.1:9001:9001 #- 127.0.0.1:9001:9001
environment: environment:
- webPort=9001
# replace webURL with your instance's target url in same format # replace webURL with your instance's target url in same format
- webURL=https://cobalt.tools/ - webURL=https://cobalt.tools/
# replace apiURL with preferred api instance url # replace apiURL with preferred api instance url

View file

@ -21,8 +21,8 @@ app.disable('x-powered-by');
await loadLoc(); await loadLoc();
const apiMode = process.env.apiURL && process.env.apiPort && !((process.env.webURL && process.env.webPort) || (process.env.selfURL && process.env.port)); const apiMode = process.env.apiURL && !process.env.webURL;
const webMode = process.env.webURL && process.env.webPort && !((process.env.apiURL && process.env.apiPort) || (process.env.selfURL && process.env.port)); const webMode = process.env.webURL && !process.env.apiURL;
if (apiMode) { if (apiMode) {
const { runAPI } = await import('./core/api.js'); const { runAPI } = await import('./core/api.js');
@ -31,5 +31,9 @@ if (apiMode) {
const { runWeb } = await import('./core/web.js'); const { runWeb } = await import('./core/web.js');
await runWeb(express, app, gitCommit, gitBranch, __dirname) await runWeb(express, app, gitCommit, gitBranch, __dirname)
} else { } else {
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`)) 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`)
)
} }

View file

@ -139,9 +139,9 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
version: version, version: version,
commit: gitCommit, commit: gitCommit,
branch: gitBranch, branch: gitBranch,
name: process.env.apiName ? process.env.apiName : "unknown", name: process.env.apiName || "unknown",
url: process.env.apiURL, url: process.env.apiURL,
cors: process.env.cors && process.env.cors === "0" ? 0 : 1, cors: process.env?.cors === "0" ? 0 : 1,
startTime: `${startTimestamp}` startTime: `${startTimestamp}`
}); });
default: default:
@ -167,12 +167,12 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
res.redirect('/api/json') res.redirect('/api/json')
}); });
app.listen(process.env.apiPort, () => { app.listen(process.env.apiPort || 9000, () => {
console.log(`\n` + console.log(`\n` +
`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` + `${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` + `Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +
`URL: ${Cyan(`${process.env.apiURL}`)}\n` + `URL: ${Cyan(`${process.env.apiURL}`)}\n` +
`Port: ${process.env.apiPort}\n` `Port: ${process.env.apiPort || 9000}\n`
) )
}); });
} }

View file

@ -76,12 +76,12 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) {
return res.redirect('/') return res.redirect('/')
}); });
app.listen(process.env.webPort, () => { app.listen(process.env.webPort || 9001, () => {
console.log(`\n` + console.log(`\n` +
`${Cyan("cobalt")} WEB ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` + `${Cyan("cobalt")} WEB ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` + `Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +
`URL: ${Cyan(`${process.env.webURL}`)}\n` + `URL: ${Cyan(`${process.env.webURL}`)}\n` +
`Port: ${process.env.webPort}\n` `Port: ${process.env.webPort || 9001}\n`
) )
}) })
} }