abtmtr-v13/index.js

91 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-08-20 19:30:37 +00:00
import express from "express";
import { config } from "dotenv";
import path from "path";
2024-08-21 06:05:24 +00:00
const __dirname = import.meta.dirname;
2024-08-20 19:30:37 +00:00
const app = express();
app.set('view engine', 'ejs');
app.use('/assets', express.static('assets'));
2024-08-21 06:05:24 +00:00
app.set('views', path.join(__dirname, "views", "pages"));
app.locals = {
visibility: [
"Backend",
"Personal",
"Friends-only",
"Login-only",
"Public"
]
}
2024-08-20 19:30:37 +00:00
config();
2024-08-21 06:05:24 +00:00
app.use(async (req, res, next) => {
const buttonsJson = await fetch("https://cdn.abtmtr.link/site_content/buttons.json")
.catch(() => res.status(500).send())
2024-08-27 07:58:49 +00:00
.then((res) => res.json())
.catch(() => res.status(500).send());
const followingJson = await fetch("https://cdn.abtmtr.link/site_content/following.json")
.catch(() => res.status(500).send())
.then((res) => res.json())
.catch(() => res.status(500).send());
2024-08-21 06:05:24 +00:00
app.locals.buttons = buttonsJson;
2024-08-27 07:58:49 +00:00
app.locals.following = followingJson;
2024-08-21 06:05:24 +00:00
next();
})
app.get('/', async (req, res) => {
const statusesJson = await fetch("https://cdn.abtmtr.link/site_content/v13/statuses.json")
.catch(() => res.status(500).send())
.then((res) => res.json());
res.render('index', {
statuses: statusesJson
});
})
app.get('/services', async (req, res) => {
const servicesJson = await fetch("https://cdn.abtmtr.link/site_content/v13/services.json")
.catch(() => res.status(500).send())
.then((res) => res.json());
res.render('services/index', { services: servicesJson });
});
app.get('/computers', async (req, res) => {
const computersJson = await fetch("https://cdn.abtmtr.link/site_content/v13/computers.json")
.catch(() => res.status(500).send())
.then((res) => res.json());
res.render('computers/index', { computers: computersJson });
});
app.get('/links', async (req, res) => {
const linksJson = await fetch("https://cdn.abtmtr.link/site_content/v13/links.json")
.catch(() => res.status(500).send())
.then((res) => res.json());
2024-08-20 19:30:37 +00:00
2024-08-21 06:05:24 +00:00
res.render('links/index', {
links: linksJson
2024-08-20 19:30:37 +00:00
});
});
2024-08-21 06:05:24 +00:00
app.get('/matkap', (req, res) => {
res.render('matkap/index');
});
app.get('/about', (req, res) => {
res.render('about/index');
});
2024-08-20 19:30:37 +00:00
app.get("/favicon.ico", (req, res) => {
res.redirect("https://cdn.abtmtr.link/site_content/favicon.ico")
})
app.listen(process.env.PORT, () => {
const url = new URL("http://localhost/");
url.port = process.env.PORT;
console.log(`Example app listening on ${url.toString()}`);
});