Static files serving

This commit is contained in:
Federico Kereki
2018-05-04 21:18:34 -03:00
parent 991fa2edd3
commit 7881f96fee
17 changed files with 78 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
/* @flow */
"use strict";
const express = require("express");
const app = express();
app.get("/", (req, res) => res.send("Server alive, with Express!"));
app.listen(8080, () => console.log("Mini server (with Express) ready at http://localhost:8080/!"));
+22
View File
@@ -0,0 +1,22 @@
/* @flow */
"use strict";
const express = require("express");
const path = require("path");
const app = express();
app.get("/", (req, res) => res.send("Server alive, with Express!"));
app.use(
"/static",
express.static(path.join(__dirname, "../flags"), {
immutable: true,
maxAge: "30 days"
})
);
app.listen(8080, () =>
console.log(
"Mini Express static server ready at http://localhost:8080/!"
)
);
+27
View File
@@ -0,0 +1,27 @@
/* @flow */
"use strict";
const express = require("express");
const app = express();
const path = require("path");
const flagsPath = path.join(__dirname, "../flags");
app.get("/uruguay", (req, res) =>
res.sendFile(`${flagsPath}/america/south/UY.png`)
);
app.get("/england", (req, res) =>
res.sendFile(`${flagsPath}/europe/GB.png`)
);
app.get("/license", (req, res) =>
res.sendFile(`${flagsPath}/license.txt`)
);
app.listen(8080, () =>
console.log(
"Mini Express static server ready at http://localhost:8080/!"
)
);