add SIGNUP_ALLOWED switch

This commit is contained in:
2023-01-12 23:22:50 +01:00
parent 5f6df65122
commit fcea6f68a4
3 changed files with 43 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
Something that tries to be a self-hosted alternative to Google Photos
Demo: https://photos.usatiuk.com
(data is stored on tmpfs, reset every day)
(no need to enter a real email, something like asdf@asdf.com is enough, data is stored on tmpfs, reset every day)
![screenshot](docs/s1.png)
@@ -30,7 +30,7 @@ Also, you need to run database migrations with
Then start with `npm run dev` and visit http://localhost:1234 (Parcel dev server
is listening at http://localhost:1234, and koa at http://localhost:3000)
## Actually hosting this thing
## Actually hosting this
The suggested way to host this is, agian, using Docker: you can find a
docker-compose example in `dockercomposeexample` folder
@@ -51,7 +51,9 @@ docker-compose example in `dockercomposeexample` folder
* `JWT_SECRET` - JWT secret - set it to something random
* `HTTPS` (`"yes"`/`"no"`) - whether the server enforce HTTPS or not
* `HTTPS` (`"yes"`/`"no"`) - whether the server enforces HTTPS or not
* `SIGNUP_ALLOWED` (`"yes"`/`"no"`) - whether signups are allowed or not, persistent
* `API_ROOT`

View File

@@ -13,7 +13,7 @@ export enum ConfigKey {
}
export interface IDBConfig {
signupAllowed: boolean;
signupAllowed: "yes" | "no";
}
const defaultValues: Record<ConfigKey, string> = {
@@ -70,6 +70,8 @@ export async function setConfigValue(
let pair = await Config.findOne({ key });
if (!pair) {
pair = new Config(key, val);
} else {
pair.value = val;
}
await pair.save();
}

View File

@@ -1,11 +1,44 @@
import { Config, ConfigKey, setConfigValue } from "~entity/Config";
import { app } from "./app";
import { config } from "./config";
import { connect } from "./config/database";
async function readConfig() {
if (process.env.SIGNUP_ALLOWED) {
if (process.env.SIGNUP_ALLOWED === "yes") {
await setConfigValue(ConfigKey.signupAllowed, "yes");
console.log("Signups enabled");
} else if (process.env.SIGNUP_ALLOWED === "no") {
await setConfigValue(ConfigKey.signupAllowed, "no");
console.log("Signups disabled");
} else {
await setConfigValue(ConfigKey.signupAllowed, "no");
console.log("Signups disabled");
}
}
}
async function dumpConfig() {
console.log("Running with config:");
//TODO: not print sensitive values
for (const entry of await Config.find()) {
console.log(`${entry.key} = ${entry.value}`);
}
}
connect()
.then((connection) => {
console.log(`Connected to ${connection.name}`);
app.listen(config.port);
console.log(`Listening at ${config.port}`);
const startApp = () => {
app.listen(config.port);
console.log(`Listening at ${config.port}`);
};
readConfig()
.then(() =>
dumpConfig()
.then(() => startApp())
.catch((e) => console.log(e)),
)
.catch((e) => console.log(e));
})
.catch((e) => console.log(e));