wiki

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

index.js (1024B)


      1 const express = require("express");
      2 const path = require("path");
      3 const fs = require("fs");
      4 
      5 const app = express();
      6 
      7 app.use(express.json());
      8 app.use(express.json({limit: '50mb'}));
      9 app.use(express.static( path.join(__dirname, "public"), { extensions: ["html", "htm"] }));
     10 
     11 // app.get("/", (req, res) => serve_html(res, "../pages/main", "index.html"))
     12 
     13 // app.get("/", (req, res) => res.send("Express test"));
     14 
     15 function startsWithAny(path, arr) {
     16     for (let i = 0; i < arr.length; ++i) {
     17         if (path.startsWith(arr[i])) return true;
     18     }
     19     return false;
     20 }
     21 
     22 app.use(express.static(path.join(__dirname, "public"), { extensions: ["html", "htm"] }));
     23 
     24 app.use((req, res) => { res.status(404).sendFile(path.join(__dirname, "public/404.html")); })
     25 
     26 const port = process.env.PORT || 3000;
     27 
     28 app.listen(port, (err, res) => {
     29     if (err) {
     30         console.log(err);
     31         return res.status(500).send(err.message);
     32     } else {
     33         console.log('[INFO] Server Running on port:', port);
     34     }
     35 })
     36 
     37 module.exports = app;
     38