Move env-based config to a separate file
This commit is contained in:
parent
7df920534c
commit
4bee0454e6
@ -2,25 +2,19 @@ import _locreq from "locreq";
|
|||||||
import Sealious, { App, LoggerMailer, SMTPMailer } from "sealious";
|
import Sealious, { App, LoggerMailer, SMTPMailer } from "sealious";
|
||||||
import type { LoggerLevel } from "sealious/@types/src/app/logger.js";
|
import type { LoggerLevel } from "sealious/@types/src/app/logger.js";
|
||||||
import { collections } from "./collections/collections.js";
|
import { collections } from "./collections/collections.js";
|
||||||
|
import {
|
||||||
|
BASE_URL,
|
||||||
|
MAILCATCHER_HOST,
|
||||||
|
MAILCATCHER_SMTP_PORT,
|
||||||
|
MAILER,
|
||||||
|
MONGO_HOST,
|
||||||
|
MONGO_PORT,
|
||||||
|
PORT,
|
||||||
|
} from "./config.js";
|
||||||
import ADMIN_CREDENTIALS from "./default-admin-credentials.js";
|
import ADMIN_CREDENTIALS from "./default-admin-credentials.js";
|
||||||
import { module_dirname } from "./util.js";
|
import { module_dirname } from "./util.js";
|
||||||
const locreq = _locreq(module_dirname(import.meta.url));
|
const locreq = _locreq(module_dirname(import.meta.url));
|
||||||
|
|
||||||
const PORT = process.env.SEALIOUS_PORT ? parseInt(process.env.SEALIOUS_PORT) : 8080;
|
|
||||||
const base_url = process.env.SEALIOUS_BASE_URL || `http://localhost:${PORT}`;
|
|
||||||
export const MONGO_PORT = process.env.SEALIOUS_MONGO_PORT
|
|
||||||
? parseInt(process.env.SEALIOUS_MONGO_PORT)
|
|
||||||
: 20747;
|
|
||||||
export const MONGO_HOST = process.env.SEALIOUS_MONGO_HOST || "127.0.0.1";
|
|
||||||
export const MAILCATCHER_HOST = process.env.SEALIOUS_MAILCATCHER_HOST || "127.0.0.1";
|
|
||||||
export const MAILCATCHER_SMTP_PORT = parseInt(
|
|
||||||
process.env.SEALIOUS_MAILCATCHER_SMTP_PORT || "1026"
|
|
||||||
);
|
|
||||||
export const MAILCATCHER_API_PORT = parseInt(
|
|
||||||
process.env.SEALIOUS_MAILCATCHER_API_PORT || "1082"
|
|
||||||
);
|
|
||||||
export const MAILER = process.env.SEALIOUS_MAILER;
|
|
||||||
|
|
||||||
declare module "koa" {
|
declare module "koa" {
|
||||||
interface BaseContext {
|
interface BaseContext {
|
||||||
$context: Sealious.Context;
|
$context: Sealious.Context;
|
||||||
@ -56,7 +50,7 @@ export default class TheApp extends App {
|
|||||||
logo: locreq.resolve("assets/logo.png"),
|
logo: locreq.resolve("assets/logo.png"),
|
||||||
version: "0.0.1",
|
version: "0.0.1",
|
||||||
default_language: "en",
|
default_language: "en",
|
||||||
base_url,
|
base_url: BASE_URL,
|
||||||
admin_email: ADMIN_CREDENTIALS.email,
|
admin_email: ADMIN_CREDENTIALS.email,
|
||||||
colors: {
|
colors: {
|
||||||
primary: "#5294a1",
|
primary: "#5294a1",
|
||||||
|
17
src/back/config.ts
Normal file
17
src/back/config.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export const SEALIOUS_SANITY = Boolean(process.env.SEALIOUS_SANITY);
|
||||||
|
export const PORT = process.env.SEALIOUS_PORT
|
||||||
|
? parseInt(process.env.SEALIOUS_PORT)
|
||||||
|
: 8080;
|
||||||
|
export const BASE_URL = process.env.SEALIOUS_BASE_URL || `http://localhost:${PORT}`;
|
||||||
|
export const MONGO_PORT = process.env.SEALIOUS_MONGO_PORT
|
||||||
|
? parseInt(process.env.SEALIOUS_MONGO_PORT)
|
||||||
|
: 20747;
|
||||||
|
export const MONGO_HOST = process.env.SEALIOUS_MONGO_HOST || "127.0.0.1";
|
||||||
|
export const MAILCATCHER_HOST = process.env.SEALIOUS_MAILCATCHER_HOST || "127.0.0.1";
|
||||||
|
export const MAILCATCHER_SMTP_PORT = parseInt(
|
||||||
|
process.env.SEALIOUS_MAILCATCHER_SMTP_PORT || "1026"
|
||||||
|
);
|
||||||
|
export const MAILCATCHER_API_PORT = parseInt(
|
||||||
|
process.env.SEALIOUS_MAILCATCHER_API_PORT || "1082"
|
||||||
|
);
|
||||||
|
export const MAILER = process.env.SEALIOUS_MAILER;
|
@ -1,16 +1,19 @@
|
|||||||
import kill from "kill-port";
|
import kill from "kill-port";
|
||||||
import _locreq from "locreq";
|
import _locreq from "locreq";
|
||||||
import TheApp from "./app.js";
|
import TheApp from "./app.js";
|
||||||
|
import { SEALIOUS_SANITY } from "./config.js";
|
||||||
import { mainRouter } from "./routes/index.js";
|
import { mainRouter } from "./routes/index.js";
|
||||||
import { module_dirname } from "./util.js";
|
import { module_dirname } from "./util.js";
|
||||||
const locreq = _locreq(module_dirname(import.meta.url));
|
const locreq = _locreq(module_dirname(import.meta.url));
|
||||||
|
|
||||||
const app = new TheApp();
|
const app = new TheApp();
|
||||||
|
|
||||||
|
console.log({ SEALIOUS_SANITY });
|
||||||
|
|
||||||
kill(app.config["www-server"].port)
|
kill(app.config["www-server"].port)
|
||||||
.then(() => app.start())
|
.then(() => app.start())
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
if (process.env.SEALIOUS_SANITY === "true") {
|
if (SEALIOUS_SANITY) {
|
||||||
console.error("Exiting with error code 0");
|
console.error("Exiting with error code 0");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
@ -18,7 +21,7 @@ kill(app.config["www-server"].port)
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (process.env.SEALIOUS_SANITY === "true") {
|
if (SEALIOUS_SANITY) {
|
||||||
console.error("EXITING WITH STATUS 1");
|
console.error("EXITING WITH STATUS 1");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,15 @@ import { v4 as uuid } from "uuid";
|
|||||||
const locreq = _locreq(module_dirname(import.meta.url));
|
const locreq = _locreq(module_dirname(import.meta.url));
|
||||||
import { SMTPMailer } from "sealious";
|
import { SMTPMailer } from "sealious";
|
||||||
import { TestUtils } from "sealious";
|
import { TestUtils } from "sealious";
|
||||||
import TheApp, {
|
import TheApp from "../app.js";
|
||||||
MAILCATCHER_API_PORT,
|
|
||||||
MAILCATCHER_HOST,
|
|
||||||
MAILCATCHER_SMTP_PORT,
|
|
||||||
} from "../app.js";
|
|
||||||
import { mainRouter } from "../routes/index.js";
|
import { mainRouter } from "../routes/index.js";
|
||||||
import { module_dirname } from "../util.js";
|
import { module_dirname } from "../util.js";
|
||||||
import getPort from "get-port";
|
import getPort from "get-port";
|
||||||
|
import {
|
||||||
|
MAILCATCHER_API_PORT,
|
||||||
|
MAILCATCHER_HOST,
|
||||||
|
MAILCATCHER_SMTP_PORT,
|
||||||
|
} from "../config.js";
|
||||||
|
|
||||||
const port_numbers = async function* () {
|
const port_numbers = async function* () {
|
||||||
yield await getPort();
|
yield await getPort();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user