adding env variables and morgan and sentry

This commit is contained in:
talksik
2022-06-03 13:30:06 -07:00
parent da5861086e
commit 6eb8092864
7 changed files with 151 additions and 37 deletions
+1 -4
View File
@@ -1,6 +1,3 @@
MONGO_CONNECTION_STRING=mongodb+srv://default:[email protected]/default?retryWrites=true&w=majority
JWT_TOKEN_SECRET=afajdslfwk1@lkkasdfl21ASDF!2
GOOGLE_AUTH_CLIENT_ID=423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com
GOOGLE_AUTH_CLIENT_SECRET=
JWT_TOKEN_SECRET=afajdslfwk1@lkkasdfl21ASDF!2
-16
View File
@@ -1,16 +0,0 @@
import dotenv from "dotenv";
if (process.env && process.env.NODE_ENV === "development") {
dotenv.config({ path: ".env.development" });
} else {
dotenv.config({ path: ".env" });
}
export const loadConfig = () => {
return {
MONGO_CONNECTION_STRING: process.env.MONGO_CONNECTION_STRING!,
JWT_TOKEN_SECRET: process.env.JWT_TOKEN_SECRET!,
GOOGLE_AUTH_CLIENT_ID: process.env.GOOGLE_AUTH_CLIENT_ID!,
GOOGLE_AUTH_CLIENT_SECRET: process.env.GOOGLE_AUTH_CLIENT_SECRET!,
};
};
+27
View File
@@ -0,0 +1,27 @@
interface EnvironmentConfig {
MONGO_CONNECTION_STRING: string;
JWT_TOKEN_SECRET: string;
GOOGLE_AUTH_CLIENT_ID: string;
}
// keep private
const getEnvironmentVariables = (): EnvironmentConfig => {
// TODO
if (process.env.NODE_ENV === 'production') {
//
}
if (process.env.NODE_ENV === 'development') {
//
}
return {
GOOGLE_AUTH_CLIENT_ID:
'423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com',
JWT_TOKEN_SECRET: 'afajdslfwk1@lkkasdfl21ASDF!2',
MONGO_CONNECTION_STRING:
'mongodb+srv://default:[email protected]/default?retryWrites=true&w=majority',
};
};
export const environmentVariables: EnvironmentConfig = getEnvironmentVariables();
+19 -4
View File
@@ -1,24 +1,39 @@
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
/* eslint-disable @typescript-eslint/no-var-requires */
import express, { Application, NextFunction, Request, Response } from 'express';
import cors from 'cors';
import morgan from 'morgan';
const app = express();
app.use(morgan('combined'));
app.use(cors());
app.use(express.json());
app.use((req: Request, res: Response, next: NextFunction) => {
console.log('Time: ', new Date());
next();
});
app.get('/', (req: Request, res: Response) => {
res.send('hello world.');
});
app.use('/api/status', (req: Request, res: Response) => {
res.json({ message: 'wohoo, server is healthy' });
});
const PORT = process.env.PORT || 8080;
const server = app.listen(PORT, () => console.log('express running'));
const server = app.listen(PORT, () =>
console.log(`express running on port | ${PORT} in host machine`),
);
// won't catch any errors here and we don't want it to
console.log();
require('socket.io')(server, {
// todo: add authentication
cors: {
origin: '*',
},
});
+8 -5
View File
@@ -14,23 +14,26 @@
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.21",
"nodemon": "^2.0.15",
"typescript": "^4.6.2",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.0"
"eslint-plugin-import": "^2.25.0",
"nodemon": "^2.0.15",
"typescript": "^4.6.2"
},
"dependencies": {
"@sentry/node": "^7.0.0",
"@sentry/tracing": "^7.0.0",
"axios": "^0.26.1",
"firebase": "^9.8.2",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"firebase": "^9.8.2",
"google-auth-library": "^7.14.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.4.1",
"morgan": "^1.10.0",
"socket.io": "^4.4.1",
"ts-node": "^10.7.0"
}
View File