Skip to content

Commit

Permalink
chore: update env setup
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Aug 4, 2024
1 parent e42de67 commit 9cca87c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
23 changes: 9 additions & 14 deletions .env.private.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
DISCORD_TOKEN=
DISCORD_CLIENT_ID=
NODE_ENV=dev
LOCAL_DATABASE_PORT=5432
NODE_ENV=dev # obviously, set to prod in prod.

AUTOMODERATOR_DISCORD_TOKEN=boop

SECRET_SIGNING_KEY=boop # generate using node -e "console.log(require('crypto').randomBytes(32).toString('base64'));"
OAUTH_DISCORD_CLIENT_SECRET=boop

# Used by Caddy directly via docker-compose for SSL certs
CF_API_TOKEN=boop
LOCAL_DOZZLE_PORT=8080
LOCAL_API_PORT=9876
ADMINS=
DATABASE_URL=postgresql://chatsift:admin@localhost:5432/chatsift
SECRET_SIGNING_KEY=32randomBytesEncodedAsBase64 # You can generate this with node -e "console.log(require('crypto').randomBytes(32).toString('base64'));"
ALLOWED_API_ORIGINS=http://localhost:3000
PUBLIC_API_URL=http://localhost:9876
OAUTH_DISCORD_CLIENT_ID=
OAUTH_DISCORD_CLIENT_SECRET=
CORS="http:\/\/localhost:3000|https:\/\/automoderator\.app"
CF_API_TOKEN=
23 changes: 18 additions & 5 deletions .env.public
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
REDIS_URL=redis://redis:6379
DISCORD_PROXY_URL=http://discord-proxy:9000
AUTOMODERATOR_GATEWAY_URL=http://gateway:9000
LOGS_DIR=/var/chatsift-logs
ROOT_DOMAIN=automoderator.app

POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_USER=chatsift
POSTGRES_PASSWORD=admin
POSTGRES_DATABASE=chatsift
LOGS_DIR=/var/chatsift-logs
API_URL=http://api:9876

REDIS_URL=redis://redis:6379

ADMINS=223703707118731264

AUTOMODERATOR_DISCORD_CLIENT_ID=878278456629157939
AUTOMODERATOR_GATEWAY_URL=http://automoderator-gateway:9000
AUTOMODERATOR_PROXY_URL=http://automoderator-proxy:9000

API_PORT=9876
PUBLIC_API_URL_DEV=http://localhost:9876
PUBLIC_API_URL_PROD=https://api-canary.automoderator.app
OAUTH_DISCORD_CLIENT_ID=1005791929075769344
CORS="http:\/\/localhost:3000|https:\/\/canary\.automoderator\.app"
ALLOWED_API_ORIGINS=http://localhost:3000,https://canary.automoderator.app
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ services:
- ./.env.private
command: ['node', '--enable-source-maps', './services/api/dist/index.js']
ports:
- 127.0.0.1:${LOCAL_API_PORT}:9876
- 127.0.0.1:${API_PORT}:{API_PORT}
volumes:
- ./logs-archive:/var/chatsift-logs

discord-proxy:
automoderator-proxy:
image: chatsift/chatsift-next:automoderator-discord-proxy
build:
context: ./
Expand All @@ -79,7 +79,7 @@ services:
volumes:
- ./logs-archive:/var/chatsift-logs

gateway:
automoderator-gateway:
image: chatsift/chatsift-next:automoderator-gateway
build:
context: ./
Expand All @@ -92,7 +92,7 @@ services:
volumes:
- ./logs-archive:/var/chatsift-logs

interactions:
automoderator-interactions:
image: chatsift/chatsift-next:automoderator-interactions
build:
context: ./
Expand All @@ -105,7 +105,7 @@ services:
volumes:
- ./logs-archive:/var/chatsift-logs

observer:
automoderator-observer:
image: chatsift/chatsift-next:automoderator-observer
build:
context: ./
Expand Down
8 changes: 5 additions & 3 deletions packages/services/core/src/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const envSchema = z.object({
// General config
NODE_ENV: z.enum(['dev', 'prod']).default('prod'),
LOGS_DIR: z.string(),
ROOT_DOMAIN: z.string(),

// DB
POSTGRES_HOST: z.string(),
Expand All @@ -34,14 +35,13 @@ const envSchema = z.object({

AUTOMODERATOR_DISCORD_TOKEN: z.string(),
AUTOMODERATOR_DISCORD_CLIENT_ID: z.string().regex(SnowflakeRegex),

AUTOMODERATOR_GATEWAY_URL: z.string().url(),

AUTOMODERATOR_PROXY_URL: z.string().url(),

// API
API_PORT: z.number(),
PUBLIC_API_URL: z.string().url(),
PUBLIC_API_URL_DEV: z.string().url(),
PUBLIC_API_URL_PROD: z.string().url(),
SECRET_SIGNING_KEY: z.string().length(44),
OAUTH_DISCORD_CLIENT_ID: z.string().regex(SnowflakeRegex),
OAUTH_DISCORD_CLIENT_SECRET: z.string(),
Expand Down Expand Up @@ -99,3 +99,5 @@ export function credentialsForCurrentBot(): BotCredentials {
}
}
}

export const API_URL = Env.NODE_ENV === 'dev' ? Env.PUBLIC_API_URL_DEV : Env.PUBLIC_API_URL_PROD;
6 changes: 3 additions & 3 deletions services/api/src/handlers/auth/discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Env, setEquals } from '@chatsift/service-core';
import { Env, setEquals, API_URL } from '@chatsift/service-core';
import { API } from '@discordjs/core';
import { badRequest, forbidden } from '@hapi/boom';
import { SnowflakeRegex } from '@sapphire/discord-utilities';
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class DiscordAuthHandler implements Registerable {
const state = new StateCookie(redirectURI).toCookie();
const params = new URLSearchParams({
client_id: Env.OAUTH_DISCORD_CLIENT_ID,
redirect_uri: `${Env.PUBLIC_API_URL}/auth/discord/callback`,
redirect_uri: `${API_URL}/auth/discord/callback`,
response_type: 'code',
scope: SCOPES,
state,
Expand Down Expand Up @@ -96,7 +96,7 @@ export default class DiscordAuthHandler implements Registerable {
client_secret: Env.OAUTH_DISCORD_CLIENT_SECRET,
code,
grant_type: 'authorization_code',
redirect_uri: `${Env.PUBLIC_API_URL}/auth/discord/callback`,
redirect_uri: `${API_URL}/auth/discord/callback`,
});

if (!setEquals(new Set(result.scope.split(' ')), new Set(SCOPES.split(' ')))) {
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/struct/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Auth {
path: '/',
sameSite: Env.NODE_ENV === 'prod' ? 'none' : 'strict',
httpOnly: true,
domain: Env.NODE_ENV === 'prod' ? '.automoderator.app' : undefined,
domain: Env.NODE_ENV === 'prod' ? `.${Env.ROOT_DOMAIN}` : undefined,
secure: Env.NODE_ENV === 'prod',
};

Expand Down

0 comments on commit 9cca87c

Please sign in to comment.