Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,48 @@


// CREATE EXPRESS APP
// Here you should create your Express app:
import express from 'express';
import morgan from 'morgan';
import projects from "./data/projects.json" with {type: "json"}
import articles from "./data/articles.json" with {type: "json"}

const app = express();



// MIDDLEWARE
// Here you should set up the required middleware:
// - `express.static()` to serve static files from the `public` folder
app.use(express.static("public"))
// - `express.json()` to parse incoming requests with JSON payloads
app.use(express.json())
// - `morgan` logger to log all incoming requests

app.use(morgan("dev"));


// ROUTES
// Start defining your routes here:
app.get('/', (req, res) => {
res.sendFile("home.html", { root: "views" });
});

app.get("/blog", (req,res) => {
res.sendFile("blog.html", { root: "views" });
})

app.get("/api/projects", (req,res) => {
res.send(projects);
})

app.get("/api/articles", (req,res) => {
res.send(articles);
})

app.use((req,res) => {
res.sendFile("not-found.html", { root: "views" });
})

// START THE SERVER
// Make your Express server listen on port 5005:
app.listen(5005, () => {
console.log("Listening to 5005")
})
Loading