Deploy to Heroku

This commit is contained in:
topjohnwu 2018-06-30 05:01:21 +08:00
parent 54eda6db0f
commit 6779ff5173
6 changed files with 22 additions and 9 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules
package-lock.json
dist
env.sh
.env

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: npm run prod

View File

@ -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'
}

View File

@ -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);

View File

@ -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;

View File

@ -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",