forked from lucaspatenaude/ScoreSpot
More dependencies split from app.js. Home screen buttons are currently not working
This commit is contained in:
41
src/app.js
41
src/app.js
@@ -13,33 +13,35 @@ const bcrypt = require("bcryptjs"); // To hash passwords
|
||||
const axios = require("axios"); // To make HTTP requests from our server. We'll learn more about it in Part C.
|
||||
const moment = require("moment"); // To extract current time data
|
||||
|
||||
// Start the Database
|
||||
const db = require("../config/database"); // Import the db module
|
||||
|
||||
// Export the app object to index.js
|
||||
module.exports = app;
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 2 : Connect to DB -->
|
||||
// *****************************************************
|
||||
|
||||
// create `ExpressHandlebars` instance and configure the layouts and partials dir.
|
||||
const hbs = handlebars.create({
|
||||
extname: "hbs",
|
||||
layoutsDir: __dirname + "/../public/views/layouts",
|
||||
partialsDir: __dirname + "/../public/views/partials",
|
||||
});
|
||||
// Start the Database
|
||||
const db = require("./database/db"); // Import the db module
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 3 : App Settings -->
|
||||
// <!-- Section 3 : Handlebars COnfiguration -->
|
||||
// *****************************************************
|
||||
|
||||
// express-handlebars is a Handlebars view engine for Express. Handlebars.js is a popular templating engine that is powerful, flexible, and helps to create reusable HTML templates.
|
||||
const hbs = require("./config/handlebars"); // Import the hbs module
|
||||
|
||||
// Register `hbs` as our view engine using its bound `engine()` function.
|
||||
app.engine("hbs", hbs.engine);
|
||||
app.set("view engine", "hbs");
|
||||
app.set("views", path.join(__dirname, "/../public/views"));
|
||||
app.set("views", path.join(__dirname, "../public/views"));
|
||||
app.use(express.static(path.join(__dirname, "../public/assets"))); // Serve asset files from the 'public/assets' directory
|
||||
app.use(bodyParser.json()); // specify the usage of JSON for parsing request body.
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 4 : Session Setup -->
|
||||
// *****************************************************
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 5 : Website Routes -->
|
||||
// *****************************************************
|
||||
|
||||
// initialize session variables
|
||||
app.get("/welcome", (req, res) => {
|
||||
res.json({ status: "success", message: "Welcome!" });
|
||||
@@ -73,10 +75,6 @@ app.use(async function (req, res, next) {
|
||||
next();
|
||||
});
|
||||
|
||||
// Serve static files from the 'public' directory
|
||||
app.use(express.static(path.join(__dirname, "/../public/assets")));
|
||||
app.use(express.static(path.join(__dirname, "/")));
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 4 : Middleware -->
|
||||
// *****************************************************
|
||||
@@ -380,3 +378,10 @@ async function getFavoriteTeamsForUser(userId) {
|
||||
throw error; // Rethrow the error for handling at a higher level
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 6 : Export the App Module to Index.js -->
|
||||
// *****************************************************
|
||||
|
||||
// Export the app object to index.js
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user