Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom client route to query the hub_id #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"hubsarray":
[
{
"hub_id": "2MCVA2f",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/camera-cube-env.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/slideconfig.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/slideshow-template.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/hubs-slide-show.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/interactable-ball.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/presence-customcmd-setup.js"
},
{
"hub_id": "8T88rLN",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/camera-cube-env.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/pdfshow-template.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/hubs-pdf-show.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/interactable-ball.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/presence-customcmd-setup.js"},
{
"hub_id": "5HsuTZ2",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/slideconfig.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/hubs-slide-show.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/slideshow-template.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/presence-customcmd-setup.js"
},
{
"hub_id": "kBquF8A",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/camera-cube-env.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/interactable-ball.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/presence-customcmd-setup.js"
},
{
"hub_id": "DVeQzPW",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/camera-cube-env.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/interactable-ball.js,https://colinfizgig.github.io/Custom-Hubs-Components/components/presence-customcmd-setup.js"
},
{
"hub_id": "xr6jnY2",
"urls":"https://colinfizgig.github.io/Custom-Hubs-Components/components/camera-cube-env.js,https://colinfizgig.github.io/aframe_Components/asteroids/js/agame.js,https://colinfizgig.github.io/aframe_Components/asteroids/js/AGameKeymapping.js,https://cdn.rawgit.com/donmccurdy/aframe-extras/v4.2.0/dist/aframe-extras.min.js,https://colinfizgig.github.io/aframe_Components/components/aframe-thumb-controls-component.min.js"
}
]
}
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ const http = require("http");
const https = require("https");
const socketIO = require("socket.io");
const express = require("express");
const cors = require('cors');
const fetch = require('node-fetch');

//load the config files which contains our hub_ids and their urls
const configUrl = 'https://colinfizgig.github.io/Custom-Hubs-Components/top-level-main-server/config.json';

let settings = { method: "Get" };
//temp variable for config
let config = {};
// promise to load config
const configPromise = fetch(configUrl, settings)
.then(res => res.json())
.then((json) => {
config = json;
return(json);
});

const app = express();
app.use(cors());

app.use(express.static("public"));

Expand All @@ -17,6 +34,33 @@ app.get(
}
);

//route for custom client to check hub_id
//hub_id is passed as a query param from the script in hub.js
// the url to hit his route should be something like...
// https://<domain for this server>/injectScripts?hubid=<hub_id>

app.get(
"/injectScripts",
async (req, res) => {
let result = {}
try{ result.success = true;}
catch(e){ result.success = false;}
finally{
var myHub = req.query.hubid;
var myUrls = "";
for (var hubObj of config.hubsarray){
if(hubObj.hub_id == myHub){
myUrls = hubObj.urls;
res.send(myUrls);
break;
}
}
if(myUrls == ""){
res.send("noUrls");
}
}
});

/////////
const privKeyFileName = "/etc/letsencrypt/live/aelatgt.net/privkey.pem";
const certFileName = "/etc/letsencrypt/live/aelatgt.net/cert.pem";
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"description": "top level node server",
"main": "index.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"fs": "0.0.1-security",
"http": "0.0.0",
"https": "^1.0.0",
"node-fetch": "^2.6.1",
"socket.io": "^2.3.0"
},
"devDependencies": {
Expand Down