-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (35 loc) 路 1.32 KB
/
Copy pathserver.js
File metadata and controls
48 lines (35 loc) 路 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// express extension: https://raw.githubusercontent.com/stopsopa/roderic/86495ef554314d388e7f6ef10ee4de6d12bcbcff/libs/express-extend-res.js?token=GHSAT0AAAAAACVQ4Q66S6J6DLZRVFB5DQLSZXEOC2Q
// const path = require("path");
import path from "path";
// const express = require("express");
import express from "express";
// https://stackoverflow.com/a/23613092
// const serveIndex = require("serve-index");
import serveIndex from "serve-index";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); // or use path.dirname('')
const host = process.env.HOST;
const port = process.env.PORT;
const web = path.resolve(__dirname);
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.all("/", (req, res) => {
res.redirect("/examples/index.html");
});
app.use(
express.static(web, {
// http://expressjs.com/en/resources/middleware/serve-static.html
// maxAge: 60 * 60 * 24 * 1000 // in milliseconds
maxAge: "356 days", // in milliseconds max-age=30758400
}),
serveIndex(web, {
icons: true,
view: "details",
hidden: false, // Display hidden (dot) files. Defaults to false.
}),
);
app.listen(port, host, () => {
console.log(`\n 馃寧 Server is running ` + `http://${host}:${port}\n`);
});