Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

56 changes: 25 additions & 31 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const app = express()
const proxy = require('http-proxy-middleware')
const path = require('path')

const configPath = './config.json'
const admindataPath = './admindata.json'
const dataPath = '../assets/data/data.json'
const logPath = '../assets/data/log.json'
const port = jsonfile.readFileSync(configPath).serverPort
const configBackupPath = '../../configBackup.json'
const configPath = process.env.LEADERBOARD_CONFIG_PATH || './config.json'
const admindataPath = process.env.LEADERBOARD_ADMINDATA_PATH || './admindata.json'
const dataPath = process.env.LEADERBOARD_DATA_PATH || '../assets/data/data.json'
const logPath = process.env.LEADERBOARD_LOG_PATH || '../assets/data/log.json'
const port = process.env.LEADERBOARD_PORT || jsonfile.readFileSync(configPath).serverPort
const configBackupPath = process.env.LEADERBOARD_CONFIG_BACKUP_PATH || '../../configBackup.json'
const proxyOption = {
target: 'http://localhost:' + port + '/',
pathRewrite: { '^/api': '' },
Expand Down Expand Up @@ -55,13 +55,15 @@ if (!fs.existsSync(admindataPath)) {
}

// spawn - `node refresh.js`
const refresh = spawn('node', ['refresh.js'], {
shell: true,
stdio: 'inherit',
})
process.on('exit', () => {
refresh.kill() // kill it when exit
})
if (process.env.LEADERBOARD_SKIP_REFRESH !== '1') {
const refresh = spawn('node', ['refresh.js'], {
shell: true,
stdio: 'inherit',
})
process.on('exit', () => {
refresh.kill() // kill it when exit
})
}

const server = http
.createServer((req, res) => {
Expand Down Expand Up @@ -104,12 +106,12 @@ const server = http
)
var contributorsList = []

Util.post(req, async (params) => {
Util.post(req, res, async (params) => {
const { token } = params
if (token === adminPassword) {
await Promise.all(
contributors.map(async (contributor) => {
const admindata = jsonfile.readFileSync('./admindata.json')
const admindata = jsonfile.readFileSync(admindataPath)
const existContributor = findContributor(
contributor,
admindata
Expand Down Expand Up @@ -176,7 +178,7 @@ const server = http
return
}

Util.post(req, (params) => {
Util.post(req, res, (params) => {
const { token, includedRepositories } = params

if (token !== adminPassword) {
Expand All @@ -197,7 +199,7 @@ const server = http
res.end('Permission denied\n')
return
}
Util.post(req, (params) => {
Util.post(req, res, (params) => {
const { token, startDate } = params

if (token !== adminPassword) {
Expand All @@ -219,7 +221,7 @@ const server = http
return
}

Util.post(req, (params) => {
Util.post(req, res, (params) => {
const { token, interval } = params

if (token !== adminPassword) {
Expand All @@ -241,7 +243,7 @@ const server = http
return
}

Util.post(req, (params) => {
Util.post(req, res, (params) => {
const { token, username } = params

if (token !== adminPassword) {
Expand Down Expand Up @@ -272,7 +274,7 @@ const server = http
return
}

Util.post(req, (params) => {
Util.post(req, res, (params) => {
const { token, username } = params

if (token !== adminPassword) {
Expand Down Expand Up @@ -410,6 +412,8 @@ const server = http
})
.listen(port)

module.exports = { server }

const io = require('socket.io')(server)
io.on('connection', (socket) => {
const intervalId = setInterval(() => {
Expand All @@ -423,14 +427,4 @@ io.on('connection', (socket) => {
})
})

function findContributor(contributorName, admindata) {
let result = null

admindata.forEach((contributor) => {
if (contributor.username === contributorName) {
result = contributor
}
})

return result
}
const findContributor = Util.findContributor
6 changes: 4 additions & 2 deletions src/server/util/API.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const axios = require('axios')
const Config = require('../config.json')
const chalk = require('chalk')

const Config = process.env.LEADERBOARD_CONFIG_PATH
? require(require('path').resolve(process.env.LEADERBOARD_CONFIG_PATH))
: require('../config.json')

const BASEURL = 'https://github.com'
const APIHOST = 'https://api.github.com'

Expand Down Expand Up @@ -35,7 +38,6 @@ async function get(url, _authToken) {
'[ERROR] Your GitHub Token is not correct! Please check it in the config.json.'
)
)
process.exit()
break
default:
console.log(chalk.yellow('[WARNING] ' + message))
Expand Down
20 changes: 17 additions & 3 deletions src/server/util/Util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function post(req, callback) {
function post(req, res, callback) {
if(req.method === 'POST') {
let body = ''

Expand All @@ -10,12 +10,26 @@ function post(req, callback) {
try {
callback(JSON.parse(body))
} catch (ex) {
return
res.writeHead(400, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ message: 'Invalid JSON body' }))
}
})
}
}

function findContributor(contributorName, admindata) {
let result = null

admindata.forEach((contributor) => {
if (contributor.username === contributorName) {
result = contributor
}
})

return result
}

module.exports = {
post
post,
findContributor
}
18 changes: 0 additions & 18 deletions tests/access.sh

This file was deleted.

12 changes: 0 additions & 12 deletions tests/api-call-tests.sh

This file was deleted.