127.0.0.1:8000 personal-website / master server / personal-website.js
master

Tree @master (Download .tar.gz)

personal-website.js @masterraw · history · blame

const express = require("express");
const app = express();
const router = express.Router();
const path = require('path');
const buildRoutes = require('./buildRoutes');
const PORT = 8080;

global.HTML_ROOT = path.join(__dirname, "../build/html/");

// Enable json parsing
app.use(express.json());

// Point to static files
app.use(express.static("./build"));

// Build all html routes defined in /routes/html
router.use(buildRoutes("/", [
    "html"
], false));

// Server will serve these pages now
app.use(router);

// Add fallbacks for unknown requests
app.use(function(req, res) {
    res.sendFile(path.join(global.HTML_ROOT, "error.html"));
});

// Start the server :D
app.listen(PORT, function() {
    console.log("Server running on port " + PORT);
});