added a home screen to jank client
This commit is contained in:
parent
04e3ac9955
commit
f2480130c1
8 changed files with 407 additions and 10 deletions
16
index.js
16
index.js
|
@ -4,7 +4,8 @@ const compression = require('compression')
|
|||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const app = express();
|
||||
const instances=require("./webpage/instances.json")
|
||||
const instances=require("./webpage/instances.json");
|
||||
const stats=require("./stats.js");
|
||||
const instancenames=new Map();
|
||||
for(const instance of instances){
|
||||
instancenames.set(instance.name,instance);
|
||||
|
@ -12,7 +13,6 @@ for(const instance of instances){
|
|||
app.use(compression())
|
||||
fetch("https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/instances/instances.json").then(_=>_.json()).then(json=>{
|
||||
for(const instance of json){
|
||||
console.log(instance);
|
||||
if(!instancenames.has(instance.name)){
|
||||
instances.push(instance);
|
||||
}else{
|
||||
|
@ -24,6 +24,7 @@ fetch("https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/instan
|
|||
}
|
||||
}
|
||||
}
|
||||
stats.observe(instances)
|
||||
})
|
||||
|
||||
app.use("/getupdates",(req, res) => {
|
||||
|
@ -145,6 +146,10 @@ async function inviteres(req,res){
|
|||
app.use('/services/oembed', (req, res) => {
|
||||
inviteres(req, res);
|
||||
})
|
||||
app.use("/uptime",(req,res)=>{
|
||||
const uptime=stats.uptime[req.query.name];
|
||||
res.send(uptime);
|
||||
})
|
||||
app.use('/', async (req, res) => {
|
||||
const scheme = req.secure ? 'https' : 'http';
|
||||
const host=`${scheme}://${req.get("Host")}`;
|
||||
|
@ -156,13 +161,14 @@ app.use('/', async (req, res) => {
|
|||
}else{
|
||||
console.log(req);
|
||||
}
|
||||
|
||||
if(req.path==="/"){
|
||||
res.sendFile(`./webpage/home.html`, {root: __dirname});
|
||||
}
|
||||
if(debugging&&req.path.startsWith("/service.js")){
|
||||
res.send("dud");
|
||||
return;
|
||||
}
|
||||
if(req.path.startsWith("/instances.json")){
|
||||
console.log("grabbed")
|
||||
res.send(JSON.stringify(instances));
|
||||
return;
|
||||
}
|
||||
|
@ -189,3 +195,5 @@ app.use('/', async (req, res) => {
|
|||
const PORT = process.env.PORT || +process.argv[1] || 8080;
|
||||
app.listen(PORT, () => {});
|
||||
console.log("this ran :P");
|
||||
|
||||
exports.getapiurls=getapiurls;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue