Created
September 26, 2020 02:13
-
-
Save avi12/c6ea74a6a716be332914d0b13122baf1 to your computer and use it in GitHub Desktop.
Current Express attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const expressPackage = | |
process.LOGONSERVER === "\\\\AVI12" ? "express-vue" : "express"; | |
const express = require(expressPackage); | |
const axios = require("axios"); | |
const app = express(); | |
const port = process.env.PORT || 8080; | |
app.use(express.static(`${__dirname}/dist/`)); | |
app.get("/", (req, res) => { | |
res.sendfile(`${__dirname}/dist/index.html`); | |
}); | |
app.post("/api/:service", async (req, res) => { | |
console.log({ req }); | |
switch (req.params.service) { | |
case "steam-id-finder": | |
{ | |
const key = process.env.STEAM_API_KEY; | |
const getSteamUrl = (type, id) => { | |
if (type === "x64") { | |
return `https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002?key=${key}&steamids=${id}`; | |
} | |
return `https://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001?key=${key}&vanityurl=${id}`; | |
}; | |
switch (req.body.getInfo) { | |
case "get-data-by-vanity-url-if-exists": | |
{ | |
let { data } = await axios( | |
getSteamUrl("vanity-url", req.body.id) | |
); | |
if (data.response.sccess === 42) { | |
res.json(data); | |
return; | |
} | |
({ data } = await axios( | |
getSteamUrl("x64", data.response.steamid) | |
)); | |
res.json(data); | |
} | |
break; | |
case "get-data-by-x64-id-if-exists": { | |
const { data } = await axios( | |
getSteamUrl("vanity-url", req.body.id) | |
); | |
const player = data.response.players[0]; | |
if (player) { | |
res.json(data); | |
return; | |
} | |
res.status(403); | |
res.send(false); | |
} | |
} | |
} | |
break; | |
} | |
}); | |
app.listen(port); | |
if (expressPackage.includes("vue")) { | |
console.log(`Listening in http://localhost:${port}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment