Skip to content

Commit

Permalink
😵 Small Schizo
Browse files Browse the repository at this point in the history
  • Loading branch information
el-ang committed Sep 5, 2022
1 parent 706a921 commit 801686e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 526 deletions.
29 changes: 14 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const { route } = require("./routes/indo");

console.time("Execution time");
console.time("\x1b[1m\x1b[96mExecution time\x1b[22m\x1b[90m");
require("dotenv").config();
let merdeka, proj, indo;
const
express = require("express"),
routes = require("./utils/routes"),
port = process.env.PORT ??= 1945,
app = express(),
pkg = require("./package.json"),
fs = require("fs"),
deploy = {vercel: process.env.VERCEL_DEPLOY},
fetch = {
at: require("node-fetch"),
github: async (req)=>{
Expand Down Expand Up @@ -40,8 +38,7 @@ const
app.locals.title = proj.name;
})
)
},
deploy = {vercel: process.env.VERCEL_DEPLOY}
}

if(deploy.vercel){
console.log("Moving static files to Build Output");
Expand All @@ -58,27 +55,29 @@ if(deploy.vercel){
module.exports = app
.set("json spaces", 1)
.set("view engine", "ejs")
.use("/indo(nesia)?:all(.json)?", require("./routes/indo"))
.use(express.static("public"), (req, res, next)=>{
let
now = new Date();
date = [{year: "numeric"}, {month: "2-digit"}, {day: "numeric"}]
.map(format=>now.toLocaleString("en-GB", {
...format,
timeZone: "Asia/Jakarta"
})).join("-"),
}))
.join("-"),
time = now.toLocaleTimeString("en-GB", {timeZone: "Asia/Jakarta"});

indo = require("./utils/algo");
merdeka = ((now = new Date(`${date}T${time}.000Z`)).getDate() == 17) && (now.getMonth() == 7);
if(!proj?.fetched || (Math.abs(new Date(proj.fetched) - new Date()) >= 108e5)) fetch.proj().then(next);
else next();
}, express.Router()
.all("/", (req, res)=>res.status(200).render(".", {merdeka, proj, page: {}}))
.all("/favicon.ico", (req, res)=>res.status(200).sendFile(`${__dirname}${deploy.vercel? "/.vercel/output": ""}/public/img/${merdeka? "17": "logo"}.svg`))
)
})
.use("/indo(nesia)?", require("./routes/indo"))
.use("/\0?(time)?zone", require("./routes/zone"))
.all("/", (req, res)=>res.status(200).render(".", {merdeka, proj, page: {}}))
.all("/favicon.ico", (req, res)=>res.status(200).sendFile(`${__dirname}${deploy.vercel? "/.vercel/output": ""}/public/img/${merdeka? "17": "logo"}.svg`))
.all("/indo(nesia)?.json", (req, res)=>res.status(200).json(indo))
.use((err, req, res, next)=>res.status(500).send(err))
.use((req, res)=>res.sendStatus(404));

app.listen(port, ()=>console.log(`GeoID | Listening on port: ${port}`));
console.timeEnd("Execution time");
app.listen(port, ()=>console.log(`\x1b[1m\x1b[38;2;255;0;0mGeo\x1b[38;2;255;255;255mID\x1b[0m \x1b[32m| \x1b[93mListening on port: \x1b[1m\x1b[95m${port}\x1b[0m`));
console.timeEnd("\x1b[1m\x1b[96mExecution time\x1b[22m\x1b[90m");
Loading

0 comments on commit 801686e

Please sign in to comment.