Okay so there's a few things going on here: 1. The main page has been split into pieces stored within views/ 2. The nav buttons are working and have a swanky animation to them 3. Some other changes throughout that I've simply lost track of from not committing frequently enough
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
var express = require('express'); // Express
|
|
var bodyParser = require('body-parser'); // Data conversion, JSON parsing
|
|
|
|
// Set up Express
|
|
var app = express();
|
|
|
|
app.use(express.static("./")); // Serve static files from root
|
|
app.use(express.json()); // Parse JSON in requests
|
|
// app.use("/", (req, res, next) => // Finally send a 404 page
|
|
// {
|
|
// res.status(404).sendFile("404.html", {"root": "./"});
|
|
// });
|
|
|
|
// Root route, respond with with index.html
|
|
app.get("/", function(req, res) {
|
|
res.sendFile("./index.html");
|
|
});
|
|
|
|
// News route, return defaultNews.json
|
|
app.get("/getnews", function(req, res) {
|
|
handleGetPosts(req, res);
|
|
});
|
|
|
|
// News route, digest received post JSON
|
|
app.post("/writenews", function(req, res) {
|
|
handleIncomingPost(req, res);
|
|
});
|
|
|
|
// Start listening
|
|
app.listen(8080, function (){
|
|
console.log("Listening on port 8080");
|
|
});
|
|
|
|
// Process incoming posts
|
|
function handleIncomingPost(req, res){
|
|
var newData = req.body;
|
|
console.log("Request object:");
|
|
console.log(newData);
|
|
res.status(204).send();
|
|
}
|
|
|
|
// Read and return current posts
|
|
function handleGetPosts(req, res)
|
|
{
|
|
res.json({});
|
|
}
|