env vars naming

This commit is contained in:
Kaushik Narayan R 2025-03-21 16:28:52 -07:00
parent 9ef4d9e044
commit 1fbab107a2
8 changed files with 36 additions and 36 deletions

10
.env
View File

@ -1,5 +1,5 @@
CLIENT_ID = your_spotify_client_id_here SPOTMGR_CLIENT_ID = your_spotify_client_id_here
CLIENT_SECRET = your_spotify_client_secret_here SPOTMGR_CLIENT_SECRET = your_spotify_client_secret_here
SESSION_SECRET = 'your_session_secret_string_here' SPOTMGR_SESSION_SECRET = 'your_session_secret_string_here'
PORT = 9001 SPOTMGR_PORT = 9001
TRUST_PROXY = 1 SPOTMGR_TRUST_PROXY = 1

View File

@ -1,5 +1,5 @@
BASE_DOMAIN = 127.0.0.1 SPOTMGR_BASE_DOMAIN = 127.0.0.1
REDIRECT_URI = http://127.0.0.1:9001/api/auth/callback SPOTMGR_REDIRECT_URI = http://127.0.0.1:9001/api/auth/callback
APP_URI = http://127.0.0.1:3000 SPOTMGR_APP_URI = http://127.0.0.1:3000
DB_URI = postgres://your_database_username:your_database_password@your_postgres_host:your_database_port/your_database_name SPOTMGR_DB_URI = postgres://your_database_username:your_database_password@your_postgres_host:your_database_port/your_database_name
REDIS_URI = redis://your_redis_host:6379 SPOTMGR_REDIS_URI = redis://your_redis_host:6379

View File

@ -1,5 +1,5 @@
BASE_DOMAIN = domain.app SPOTMGR_BASE_DOMAIN = domain.app
REDIRECT_URI = https://backend.app/api/auth/callback SPOTMGR_REDIRECT_URI = https://backend.app/api/auth/callback
APP_URI = https://frontend.app SPOTMGR_APP_URI = https://frontend.app
DB_URI = postgres://your_database_username:your_database_password@your_postgres_host:your_database_port/your_database_name SPOTMGR_DB_URI = postgres://your_database_username:your_database_password@your_postgres_host:your_database_port/your_database_name
REDIS_URI = redis://your_redis_host:6379 SPOTMGR_REDIS_URI = redis://your_redis_host:6379

View File

@ -13,7 +13,7 @@ const authInstance: AxiosInstance = axios.create({
Authorization: Authorization:
"Basic " + "Basic " +
Buffer.from( Buffer.from(
process.env["CLIENT_ID"] + ":" + process.env["CLIENT_SECRET"] process.env["SPOTMGR_CLIENT_ID"] + ":" + process.env["SPOTMGR_CLIENT_SECRET"]
).toString("base64"), ).toString("base64"),
}, },
}); });

View File

@ -2,12 +2,12 @@ import { createClient } from "redis";
import logger from "../utils/logger.ts"; import logger from "../utils/logger.ts";
if (!process.env["REDIS_URI"]) if (!process.env["SPOTMGR_REDIS_URI"])
throw new TypeError("Redis connection URI not defined"); throw new TypeError("Redis connection URI not defined");
// Initialize // Initialize
const redisClient: ReturnType<typeof createClient> = createClient({ const redisClient: ReturnType<typeof createClient> = createClient({
url: process.env["REDIS_URI"], url: process.env["SPOTMGR_REDIS_URI"],
socket: { socket: {
keepAlive: 25 * 1000, // 25s keepAlive: 25 * 1000, // 25s
connectTimeout: 15 * 1000, connectTimeout: 15 * 1000,

View File

@ -10,13 +10,13 @@ type ConnConfigs = Record<string, SeqOptsWithURI>;
// env-specific config // env-specific config
const connConfigs: ConnConfigs = { const connConfigs: ConnConfigs = {
development: { development: {
use_env_variable: "DB_URI", use_env_variable: "SPOTMGR_DB_URI",
}, },
test: { test: {
use_env_variable: "DB_URI", use_env_variable: "SPOTMGR_DB_URI",
}, },
production: { production: {
use_env_variable: "DB_URI", use_env_variable: "SPOTMGR_DB_URI",
// dialectOptions: { // dialectOptions: {
// ssl: true, // ssl: true,
// }, // },

View File

@ -25,9 +25,9 @@ const login: RequestHandler = async (_req, res) => {
`${accountsAPIURL}/authorize?` + `${accountsAPIURL}/authorize?` +
new URLSearchParams({ new URLSearchParams({
response_type: "code", response_type: "code",
client_id: process.env["CLIENT_ID"], client_id: process.env["SPOTMGR_CLIENT_ID"],
scope: Object.values(requiredScopes).join(" "), scope: Object.values(requiredScopes).join(" "),
redirect_uri: process.env["REDIRECT_URI"], redirect_uri: process.env["SPOTMGR_REDIRECT_URI"],
state: state, state: state,
} as Record<string, string>).toString() } as Record<string, string>).toString()
); );
@ -63,7 +63,7 @@ const callback: RequestHandler = async (req, res) => {
const authForm = { const authForm = {
code: code, code: code,
redirect_uri: process.env["REDIRECT_URI"], redirect_uri: process.env["SPOTMGR_REDIRECT_URI"],
grant_type: "authorization_code", grant_type: "authorization_code",
} as Record<string, string>; } as Record<string, string>;
@ -98,7 +98,7 @@ const callback: RequestHandler = async (req, res) => {
}; };
// res.status(200).send({ message: "OK" }); // res.status(200).send({ message: "OK" });
res.redirect(process.env["APP_URI"] + "?login=success"); res.redirect(process.env["SPOTMGR_APP_URI"] + "?login=success");
logger.debug("New login.", { username: resp.data.display_name }); logger.debug("New login.", { username: resp.data.display_name });
return null; return null;
} }
@ -167,7 +167,7 @@ const logout: RequestHandler = async (req, res) => {
} else { } else {
res.clearCookie(sessionName); res.clearCookie(sessionName);
// res.status(200).send({ message: "OK" }); // res.status(200).send({ message: "OK" });
res.redirect(process.env["APP_URI"] + "?logout=success"); res.redirect(process.env["SPOTMGR_APP_URI"] + "?logout=success");
logger.debug("Logged out.", { sessionID: delSession.id }); logger.debug("Logged out.", { sessionID: delSession.id });
} }
}); });

View File

@ -26,17 +26,17 @@ const app = express();
// check env vars // check env vars
if ( if (
isNaN(Number(process.env["TRUST_PROXY"])) || isNaN(Number(process.env["SPOTMGR_TRUST_PROXY"])) ||
![0, 1].includes(Number(process.env["TRUST_PROXY"])) ![0, 1].includes(Number(process.env["SPOTMGR_TRUST_PROXY"]))
) { ) {
throw new TypeError("TRUST_PROXY must be 0 or 1"); throw new TypeError("SPOTMGR_TRUST_PROXY must be 0 or 1");
} }
if (!process.env["SESSION_SECRET"]) { if (!process.env["SPOTMGR_SESSION_SECRET"]) {
throw new TypeError("SESSION_SECRET cannot be undefined"); throw new TypeError("SPOTMGR_SESSION_SECRET cannot be undefined");
} }
// Enable this if you run behind a proxy (e.g. nginx) // Enable this if you run behind a proxy (e.g. nginx)
app.set("trust proxy", process.env["TRUST_PROXY"]); app.set("trust proxy", process.env["SPOTMGR_TRUST_PROXY"]);
const redisStore = new RedisStore({ client: redisClient }); const redisStore = new RedisStore({ client: redisClient });
@ -45,11 +45,11 @@ app.use(
session({ session({
name: sessionName, name: sessionName,
store: redisStore, store: redisStore,
secret: process.env["SESSION_SECRET"], secret: process.env["SPOTMGR_SESSION_SECRET"],
resave: false, resave: false,
saveUninitialized: false, saveUninitialized: false,
cookie: { cookie: {
domain: process.env["BASE_DOMAIN"], domain: process.env["SPOTMGR_BASE_DOMAIN"],
httpOnly: true, // if true prevent client side JS from reading the cookie httpOnly: true, // if true prevent client side JS from reading the cookie
maxAge: 7 * 24 * 60 * 60 * 1000, // 1 week maxAge: 7 * 24 * 60 * 60 * 1000, // 1 week
sameSite: process.env["NODE_ENV"] === "development" ? "lax" : "none", // cross-site for production sameSite: process.env["NODE_ENV"] === "development" ? "lax" : "none", // cross-site for production
@ -60,7 +60,7 @@ app.use(
app.use( app.use(
cors({ cors({
origin: process.env["APP_URI"], origin: process.env["SPOTMGR_APP_URI"],
credentials: true, credentials: true,
}) })
); );
@ -121,7 +121,7 @@ app.use((req, res) => {
return null; return null;
}); });
const port = process.env["PORT"] || 5000; const port = process.env["SPOTMGR_PORT"] || 5000;
const server = app.listen(port, () => { const server = app.listen(port, () => {
logger.info(`App Listening on port ${port}`); logger.info(`App Listening on port ${port}`);