Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
crizmo committed Jul 10, 2023
0 parents commit e955492
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
package-lock.json
55 changes: 55 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fetch from "node-fetch";
import express from "express";

const app = express();
const port = 3000;

app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});

// Array to store the URLs
const urls = [
"https://discord-cards.kurizu.repl.co/api/compact/784141856426033233",
// Add more URLs here
];

const fetchData = async (url) => {
try {
const response = await fetch(url);
const status = response.status;
return status;
} catch (error) {
console.error(`Error fetching data from ${url}:`, error);
return console.error;
}
};

const keepReplAlive = () => {
// Fetch data for each URL
urls.forEach((url) => {
fetchData(url);
});
};

setInterval(keepReplAlive, 25 * 60 * 1000); // 25 minutes

app.get("/", (req, res) => {
res.send("Server is running");
});

app.get("/status", async (req, res) => {
const statusList = {};
for (const url of urls) {
const status = await fetchData(url);
statusList[url] = status;
}
res.json(statusList);
});

app.get("/keepalive", (req, res) => {
res.send("Keep-alive is working!");
});

// export the app for testing
export default app;
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "repler",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"node-fetch": "^3.3.1"
}
}
15 changes: 15 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "index.js",
"use": "@now/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "index.js"
}
]
}

0 comments on commit e955492

Please sign in to comment.