mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 01:23:08 +03:00
refactors: textile service uptime check
This commit is contained in:
parent
3bd1158392
commit
42afbb8eaa
@ -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)) {
|
||||
|
51
server.js
51
server.js
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user