120 lines
2.7 KiB
JavaScript
120 lines
2.7 KiB
JavaScript
//! Deps
|
|
const express = require("express");
|
|
const helmet = require("helmet");
|
|
const compression = require("compression");
|
|
const cors = require("cors");
|
|
const morgan = require("morgan");
|
|
const chalk = require("chalk");
|
|
const hbs = require("express-handlebars");
|
|
let { port, hostname } = {
|
|
port: 48114,
|
|
};
|
|
const con = require("./constants");
|
|
|
|
const app = express();
|
|
|
|
app.engine(
|
|
"hbs",
|
|
hbs({
|
|
extname: "hbs",
|
|
defaultView: "default",
|
|
})
|
|
);
|
|
|
|
app.set("view engine", "hbs");
|
|
app.set("json spaces", 4);
|
|
app.use("/assets", express.static("./assets"));
|
|
app.use(express.json());
|
|
app.use(
|
|
express.urlencoded({
|
|
extended: true,
|
|
})
|
|
);
|
|
app.use(helmet());
|
|
app.use(compression());
|
|
app.use(cors());
|
|
// Logging
|
|
app.use(
|
|
morgan((tokens, req, res) => {
|
|
return [
|
|
chalk.hex("#34ace0").bold(`[ ${tokens.method(req, res)} ]`),
|
|
chalk.hex("#ffb142").bold(tokens.status(req, res)),
|
|
chalk.hex("#ff5252").bold(req.hostname + tokens.url(req, res)),
|
|
chalk.hex("#2ed573").bold(tokens["response-time"](req, res) + "ms"),
|
|
chalk.hex("#f78fb3").bold("@ " + tokens.date(req, res)),
|
|
].join(" ");
|
|
})
|
|
);
|
|
|
|
function breakSocials(social) {
|
|
// if (typeof social !== String) throw new Error('This social media is not a string :eyes:')
|
|
return social.split("");
|
|
}
|
|
|
|
module.exports = (async) => {
|
|
app.get("/", async (req, res) => {
|
|
res.render("index", {
|
|
layout: "main",
|
|
name: con.name,
|
|
host: req.hostname,
|
|
social: [
|
|
{
|
|
name: "Twitter",
|
|
link: "abisu.net/twitter",
|
|
character: breakSocials("Twitter"),
|
|
},
|
|
{
|
|
name: "Spotify",
|
|
link: "abisu.net/spotify",
|
|
character: breakSocials("Spotify"),
|
|
},
|
|
{
|
|
name: "Audius",
|
|
link: "abisu.net/audius",
|
|
character: breakSocials("Audius"),
|
|
},
|
|
{
|
|
name: "Soundcloud",
|
|
link: "abisu.net/soundcloud",
|
|
character: breakSocials("Soundcloud"),
|
|
},
|
|
{
|
|
name: "Bandcamp",
|
|
link: "abisu.net/bandcamp",
|
|
character: breakSocials("Bandcamp"),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
con.socials.forEach((social) => {
|
|
app.get(social.links, (req, res) => {
|
|
res.redirect(social.link);
|
|
});
|
|
});
|
|
|
|
// ! STEMS
|
|
|
|
app.get("/stems/:stem", async (req, res) => {
|
|
switch (req.params.stem) {
|
|
case "overdrive":
|
|
case "909":
|
|
return res.download(
|
|
"./assets/files/909_(overdrive)_STEMS.zip",
|
|
"909_Overdrive_Stems.zip"
|
|
);
|
|
|
|
default:
|
|
return res.redirect("/");
|
|
}
|
|
});
|
|
|
|
// Music
|
|
app.get("/overdrive", (req, res) => {
|
|
res.redirect(con.music.overdrive);
|
|
});
|
|
|
|
app.listen(port /* , hostname */, () => {
|
|
console.log(`[ Server ] Listening on ${port}`);
|
|
});
|
|
};
|