Skip to content

Commit

Permalink
Adding configuration files
Browse files Browse the repository at this point in the history
To make this less hardcoded
  • Loading branch information
TrinitroToluen0 committed Jun 1, 2023
1 parent 4d3d056 commit 0f49305
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
.env
src/logs/console.log
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require("dotenv").config();

module.exports = {
PORT: 3000,
MONGO_URI: process.env.MONGO_URI,
SESSION_SECRET: process.env.SESSION_SECRET
};
4 changes: 0 additions & 4 deletions config.json

This file was deleted.

29 changes: 23 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@types/node": "^18.0.6",
"bcrypt": "^5.1.0",
"dotenv": "^16.1.3",
"ejs": "^3.1.9",
"express": "^4.18.2",
"express-session": "^1.17.3",
Expand Down
3 changes: 2 additions & 1 deletion src/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const config = require("../config.js")
const mongoose = require("mongoose");
const ObjectId = mongoose.Types.ObjectId;
const uri = "mongodb+srv://Mencoreh:[email protected]/ChatApp?retryWrites=true&w=majority";
const uri = config.MONGO_URI;
//CONEXIÓN A MONGODB
mongoose
.connect(uri, {
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Inicializar el servidor express y requerir dependencias
const config = require("../config.json")
const config = require("../config.js")
const express = require("express");
const app = express();
const path = require("path");
Expand All @@ -12,7 +12,7 @@ const SocketIO = require("socket.io");

// Usar express-sesion para manejar las sesiones
const sessionMiddleware = session({
secret: config.sessionSecret,
secret: config.SESSION_SECRET,
resave: false,
saveUninitialized: true,
});
Expand All @@ -32,8 +32,8 @@ app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));

// Inicializar el servidor y establecer Socket.IO
const server = app.listen(config.port, "0.0.0.0", () => {
console.log(`Servidor Express funcionando en http://0.0.0.0:${config.port}`);
const server = app.listen(config.PORT, "0.0.0.0", () => {
console.log(`Servidor Express funcionando en http://0.0.0.0:${config.PORT}`);
});
const io = SocketIO(server);

Expand Down

0 comments on commit 0f49305

Please sign in to comment.