first commit
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s

This commit is contained in:
Elijah 2026-10-20 19:04:12 -07:00
commit 6fc0a01c56
51 changed files with 11319 additions and 0 deletions

49
server/index.js Normal file
View file

@ -0,0 +1,49 @@
import { mkdirSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
import { openDatabase } from "./db.js";
import { createApp } from "./app.js";
import { hashPassword } from "./auth.js";
const secret = (name) =>
process.env[name + "_FILE"]
? readFileSync(process.env[name + "_FILE"], "utf8").trimEnd()
: process.env[name];
const password = secret("CALIO_PASSWORD");
const passwordHash =
secret("CALIO_PASSWORD_HASH") || (password && hashPassword(password));
if (!passwordHash || !/^scrypt:[a-f0-9]{32}:[a-f0-9]{128}$/.test(passwordHash))
throw new Error(
"Configure CALIO_PASSWORD_HASH[_FILE] or CALIO_PASSWORD[_FILE]. There are no default credentials.",
);
if (password && password.length < 12)
throw new Error("CALIO_PASSWORD must be at least 12 characters.");
const origin = process.env.APP_ORIGIN || "http://localhost:3000";
if (new URL(origin).origin !== origin)
throw new Error("APP_ORIGIN must be an origin without a trailing slash");
const secureCookies = process.env.COOKIE_SECURE !== "false";
if (
!secureCookies &&
!["localhost", "127.0.0.1"].includes(new URL(origin).hostname)
)
throw new Error(
"Insecure cookies are allowed only on localhost. Use HTTPS for deployment.",
);
const dataDir = resolve(process.env.DATA_DIR || "data");
mkdirSync(dataDir, { recursive: true });
const store = openDatabase(resolve(dataDir, "calio.sqlite"));
const app = createApp({
store,
username: process.env.CALIO_USERNAME || "calio",
passwordHash,
origin,
secureCookies,
});
const server = app.listen(Number(process.env.PORT || 3000), "0.0.0.0", () =>
console.log(`Calio listening at ${origin}`),
);
for (const signal of ["SIGTERM", "SIGINT"])
process.on(signal, () =>
server.close(() => {
store.close();
process.exit(0);
}),
);