refactors: textile service uptime check

This commit is contained in:
@wwwjim 2020-08-19 22:57:46 -07:00
parent 3bd1158392
commit 42afbb8eaa
2 changed files with 37 additions and 33 deletions

View File

@ -16,6 +16,25 @@ const TEXTILE_KEY_INFO = {
secret: Environment.TEXTILE_HUB_SECRET,
};
export const checkTextile = async () => {
try {
const response = await fetch("https://hub.textile.io/health", {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
if (response.status === 204) {
return true;
}
} catch (e) {
console.log(e);
}
return false;
};
export const getIdFromCookie = (req) => {
let id;
if (!Strings.isEmpty(req.headers.cookie)) {

View File

@ -30,26 +30,27 @@ app.prepare().then(async () => {
server.use("/public", express.static("public"));
server.get("/_", async (req, res) => {
// NOTE(jim): Move health check into a utility method.
let buckets = null;
try {
const response = await fetch("https://hub.textile.io/health", {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
server.get("/system", async (req, res) => {
res.redirect("/_/system");
});
if (response.status === 204) {
buckets = true;
}
} catch (e) {
console.log(e);
}
server.get("/experiences", async (req, res) => {
res.redirect("/_/system");
});
server.get("/system/:component", async (req, res) => {
res.redirect(`/_/system/${req.params.component}`);
});
server.get("/experiences/:module", async (req, res) => {
res.redirect(`/_/experiences/${req.params.module}`);
});
server.get("/_", async (req, res) => {
const isBucketsAvailable = await Utilities.checkTextile();
// TODO(jim): Do something more robust here.
if (!buckets) {
if (!isBucketsAvailable) {
return res.redirect("/maintenance");
}
@ -69,22 +70,6 @@ app.prepare().then(async () => {
});
});
server.get("/system", async (req, res) => {
res.redirect("/_/system");
});
server.get("/experiences", async (req, res) => {
res.redirect("/_/system");
});
server.get("/system/:component", async (req, res) => {
res.redirect(`/_/system/${req.params.component}`);
});
server.get("/experiences/:module", async (req, res) => {
res.redirect(`/_/experiences/${req.params.module}`);
});
server.get("/:username", async (req, res) => {
// TODO(jim): Temporary workaround
if (!Validations.userRoute(req.params.username)) {