Skip to content

Commit

Permalink
DISABLE_WEB added
Browse files Browse the repository at this point in the history
  • Loading branch information
patheticGeek committed Jun 6, 2020
1 parent c425fa1 commit cae62b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Please dont start a test torrent download on my website it works you dont need t

## TODO after deploy

### To disable website

If you only want telegram bot to be workinh set value of DISABLE_WEB env var to true.

### To get torrent download working:

Set a variable with key "SITE" and value is the link of your site. eg. "https://\<project name>.herokuapp.com". This is important to keep bot alive or server will stop after 30 min of inactivity.
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ const details = require("./routes/details");
const torrent = require("./routes/torrent");

const dev = process.env.NODE_ENV !== "production";
const allowWeb = !process.env.DISABLE_WEB;
const PORT = parseInt(process.env.PORT, 10) || 3000;

const server = express();

keepalive();

// if (!dev) {
// server.use((req, res, next) => {
// req.headers.host.indexOf("https://") !== 0 ? next() : res.redirect("https://" + req.headers.host + req.url);
// });
// }

server.use(compression());
server.use(bodyParser.json());
server.use((req, res, next) => {
Expand Down Expand Up @@ -91,8 +86,13 @@ server.get("/api/v1/status", async (req, res) => {
res.send(currStatus);
});

server.use("/static", express.static("web/build/static"));
server.all("*", (req, res) => res.sendFile("web/build/index.html", { root: __dirname }));
if (allowWeb) {
console.log("web allowed");
server.use("/static", express.static("web/build/static"));
server.all("*", (req, res) => res.sendFile("web/build/index.html", { root: __dirname }));
} else {
console.log("web disabled");
}

server.listen(PORT, () => {
console.log(`> Running on http://localhost:${PORT}`);
Expand Down

0 comments on commit cae62b2

Please sign in to comment.