11const express = require ( "express" ) ;
2- const bodyParser = require ( "body-parser" ) ; // Required for parsing request bodies
2+ const bodyParser = require ( "body-parser" ) ;
33const cors = require ( "cors" ) ;
44const helmet = require ( "helmet" ) ;
55const morgan = require ( "morgan" ) ;
@@ -9,6 +9,7 @@ const Song = require("./models/Song");
99const Album = require ( "./models/Album" ) ;
1010const { getAlbum } = require ( "./controllers/albumController" ) ;
1111const { getSong } = require ( "./controllers/songController" ) ;
12+ const setHeaderInformation = require ( "./middlewares/setHeaderInformation" ) ;
1213const app = express ( ) ;
1314const port = 3000 ;
1415
@@ -20,16 +21,10 @@ app.use(helmet());
2021app . use ( morgan ( "dev" ) ) ;
2122app . use ( bodyParser . json ( ) ) ; // Parse JSON requests
2223
23- // Specify the path to the images folder
24- const imagesPath = path . join ( __dirname , "/public/images" ) ;
25- // Serve static files from the images folder
26- app . use ( "/images" , express . static ( imagesPath ) ) ;
24+ app . use ( "/images" , express . static ( path . join ( __dirname , "/public/images" ) ) ) ; // Serve static files from the images folder
2725
28- // Set EJS as the view engine
29- app . set ( "view engine" , "ejs" ) ;
30-
31- // Specify the directory where your views/templates are located (optional)
32- app . set ( "views" , path . join ( __dirname , "views" ) ) ;
26+ app . set ( "view engine" , "ejs" ) ; // Serve static files from the images folder
27+ app . set ( "views" , path . join ( __dirname , "views" ) ) ; // Specify the views directory
3328
3429app . get ( "/" , async ( req , res ) => {
3530 const githubLink = "https://github.com/lakshaykamat/taylor-swift-api" ;
@@ -42,10 +37,11 @@ app.get("/", async (req, res) => {
4237 appName : "Taylor Swift API" ,
4338 } ) ;
4439} ) ;
40+ app . use ( setHeaderInformation ) ; // Set Header information to all routes
4541
46- // Use routes from separate files
4742app . use ( "/albums" , require ( "./routes/album" ) ) ;
4843app . use ( "/songs" , require ( "./routes/song" ) ) ;
44+ app . use ( "/quotes" , require ( "./routes/quote" ) ) ;
4945
5046app . get ( "/album/:name" , getAlbum ) ;
5147app . get ( "/song/:name" , getSong ) ;
0 commit comments