Skip to content

Commit

Permalink
fix: update environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarogfn committed Apr 25, 2024
1 parent 74f2e67 commit b92cbed
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
11 changes: 2 additions & 9 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@


# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

PORT=3000
HOSTNAME=localhost
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
2 changes: 2 additions & 0 deletions src/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Express from 'express';
import setupRoutes from './routes.js';
import setupMiddlewares from './middlewares.js';
import { setupHealthCheck } from './healthcheck.js';

const app = Express();

setupRoutes(app);
setupMiddlewares(app);
setupHealthCheck(app);

export default app;
14 changes: 6 additions & 8 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ if (process.env['MODE'] === 'DEV') {
dotenv.config({
path: ['.env.dev', '.env'],
});
}

if (process.env['MODE'] === 'PROD') {
} else if (process.env['MODE'] === 'PROD') {
dotenv.config({
path: ['.env.prod', '.env'],
});
}

if (process.env['MODE'] === 'QA') {
} else if (process.env['MODE'] === 'QA') {
dotenv.config({
path: ['.env.qa', '.env'],
});
} else {
dotenv.config({
path: ['.env'],
});
}

export default {
PORT: process.env['PORT'],
HOSTNAME: process.env['HOSTNAME'],
OAUTH_MASTODON_CLIENT_SECRET: process.env['OAUTH_MASTODON_CLIENT_SECRET'],
OAUTH_MASTODON_CLIENT_ID: process.env['OAUTH_MASTODON_CLIENT_ID'],
} as Record<string, string>;
2 changes: 1 addition & 1 deletion src/config/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpStatusCode } from '@/shared/protocols/http-client.js';
import { Express } from 'express';

export default (app: Express): void => {
export const setupHealthCheck = (app: Express): void => {
app.get('/healthcheck', (req, res) => {
res.status(HttpStatusCode.ok).json({ status: 'Running :)' });
});
Expand Down
2 changes: 0 additions & 2 deletions src/config/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { Express } from 'express';
import { cors } from '@/middlewares/cors/cors.js';
import { bodyParser } from '@/middlewares/body-parser/body-parser.js';
import healthcheck from './healthcheck.js';

export default function setupMiddlewares(app: Express): void {
app.use(bodyParser);
app.use(cors);
app.use(healthcheck);
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import app from './config/app.js';

function startServer() {
const listener = app.listen(Number(env.PORT), env.HOSTNAME, () => {
console.log(`Server running at http://localhost:${env.PORT}`);
console.log(`Server running at http://${env.HOSTNAME}:${env.PORT}`);
});

listener.on('error', (err) => {
Expand Down

0 comments on commit b92cbed

Please sign in to comment.