api & web: ports in env are no longer strictly required
This commit is contained in:
parent
3e8c059a3a
commit
afab7f94a7
4 changed files with 13 additions and 11 deletions
|
@ -17,7 +17,6 @@ services:
|
|||
#- 127.0.0.1:9000:9000
|
||||
|
||||
environment:
|
||||
- apiPort=9000
|
||||
# replace apiURL with your instance's target url in same format
|
||||
- apiURL=https://co.wuk.sh/
|
||||
# replace apiName with your instance's distinctive name
|
||||
|
@ -48,7 +47,6 @@ services:
|
|||
#- 127.0.0.1:9001:9001
|
||||
|
||||
environment:
|
||||
- webPort=9001
|
||||
# replace webURL with your instance's target url in same format
|
||||
- webURL=https://cobalt.tools/
|
||||
# replace apiURL with preferred api instance url
|
||||
|
|
|
@ -21,8 +21,8 @@ app.disable('x-powered-by');
|
|||
|
||||
await loadLoc();
|
||||
|
||||
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));
|
||||
const apiMode = process.env.apiURL && !process.env.webURL;
|
||||
const webMode = process.env.webURL && !process.env.apiURL;
|
||||
|
||||
if (apiMode) {
|
||||
const { runAPI } = await import('./core/api.js');
|
||||
|
@ -31,5 +31,9 @@ if (apiMode) {
|
|||
const { runWeb } = await import('./core/web.js');
|
||||
await runWeb(express, app, gitCommit, gitBranch, __dirname)
|
||||
} 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`)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -139,9 +139,9 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
|||
version: version,
|
||||
commit: gitCommit,
|
||||
branch: gitBranch,
|
||||
name: process.env.apiName ? process.env.apiName : "unknown",
|
||||
name: process.env.apiName || "unknown",
|
||||
url: process.env.apiURL,
|
||||
cors: process.env.cors && process.env.cors === "0" ? 0 : 1,
|
||||
cors: process.env?.cors === "0" ? 0 : 1,
|
||||
startTime: `${startTimestamp}`
|
||||
});
|
||||
default:
|
||||
|
@ -167,12 +167,12 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
|||
res.redirect('/api/json')
|
||||
});
|
||||
|
||||
app.listen(process.env.apiPort, () => {
|
||||
app.listen(process.env.apiPort || 9000, () => {
|
||||
console.log(`\n` +
|
||||
`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
|
||||
`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +
|
||||
`URL: ${Cyan(`${process.env.apiURL}`)}\n` +
|
||||
`Port: ${process.env.apiPort}\n`
|
||||
`Port: ${process.env.apiPort || 9000}\n`
|
||||
)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -76,12 +76,12 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) {
|
|||
return res.redirect('/')
|
||||
});
|
||||
|
||||
app.listen(process.env.webPort, () => {
|
||||
app.listen(process.env.webPort || 9001, () => {
|
||||
console.log(`\n` +
|
||||
`${Cyan("cobalt")} WEB ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
|
||||
`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +
|
||||
`URL: ${Cyan(`${process.env.webURL}`)}\n` +
|
||||
`Port: ${process.env.webPort}\n`
|
||||
`Port: ${process.env.webPort || 9001}\n`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue