diff --git a/.gitignore b/.gitignore index 0ff8343..a9022ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules package-lock.json dist -env.sh +.env \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..403c9db --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: npm run prod diff --git a/lib/Shared.js b/lib/Shared.js index f4205da..3d45711 100644 --- a/lib/Shared.js +++ b/lib/Shared.js @@ -2,7 +2,8 @@ import Github from './Github'; if (process.env.MAGISK_SERVER_USERNAME === undefined || process.env.MAGISK_SERVER_TOKEN === undefined || - process.env.MAGISK_SERVER_PORT === undefined) { + process.env.MAGISK_SERVER_DOMAIN === undefined || + process.env.PORT === undefined) { throw 'Error: Please setup environment variables' } diff --git a/lib/index.js b/lib/index.js index 421d13d..7c36582 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,9 +6,10 @@ import { submissions, magiskRepo, ID_SET } from './Shared'; magiskRepo.getRepos().then(res => res.data).then(repos => { // Add all repos to the set repos.forEach(repo => ID_SET.add(repo.description)); - repos.forEach(RepoModerator); submissions.listIssues().then(res => res.data.forEach(SubmissionHandler)); - // Start the server to monitor webhooks - server.listen(process.env.MAGISK_SERVER_PORT, - () => console.log(`Server listening to ${process.env.MAGISK_SERVER_PORT}`)); + // Start the server + server.listen(process.env.PORT, () => console.log(`Server listening to ${process.env.PORT}`)); }) + +// Run full scan every hour +setInterval(() => magiskRepo.getRepos().then(res => res.data.forEach(RepoModerator)), 60 * 60 * 1000); diff --git a/lib/server.js b/lib/server.js index 002a244..789002c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,5 +1,6 @@ import express from 'express'; import bodyParser from 'body-parser'; +import axios from 'axios'; import SubmissionHandler from './SubmissionHandler'; import RepoModerator from './RepoModerator'; @@ -21,7 +22,11 @@ server.post('/moderate', (req, res) => { RepoModerator(req.body.repository); } res.send(); -}) +}); + +server.get('/ping', (req, res) => res.send('PING!')); + +// Wake Heroku every 15 mins +setInterval(() => axios.get(`${process.env.MAGISK_SERVER_DOMAIN}/ping`).then(res => console.log(res.data)), 15 * 60 * 1000); export default server; - diff --git a/package.json b/package.json index df18b8d..3acd811 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,16 @@ "version": "1.0.0", "description": "Auto handle new module requests", "main": "lib/index.js", + "engines": { + "node": "8.10.x", + "npm": "6.1.x" + }, "scripts": { "start": "babel-node lib/index.js", "nodemon": "nodemon lib/index.js --exec babel-node", - "build": "babel lib -d dist", + "build": "rm -rf dist && babel lib -d dist", "prod": "node dist/index.js", + "heroku-postbuild": "npm run build", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "topjohnwu",