Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): split leaderboard into separate containers #305

Merged
merged 3 commits into from
May 30, 2020
Merged
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
5 changes: 3 additions & 2 deletions config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const config = {
password: process.env.RCTF_REDIS_PASSWORD,
database: process.env.RCTF_REDIS_DATABASE
},
migrate: process.env.RCTF_DATABASE_MIGRATE || 'never'
migrate: process.env.RCTF_DATABASE_MIGRATE || 'never' // enum: never, before, only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to move these into actual enum types at some point

},
email: {
smtpUrl: process.env.RCTF_SMTP_URL,
Expand All @@ -57,7 +57,8 @@ const config = {
ctftimeClientSecret: process.env.RCTF_CTFTIME_CLIENT_SECRET,
loginTimeout: 10 * 60 * 1000,
startTime: parseInt(process.env.RCTF_START_TIME) || Date.now() - 24 * 60 * 60 * 1000,
endTime: parseInt(process.env.RCTF_END_TIME) || Date.now() + 24 * 60 * 60 * 1000
endTime: parseInt(process.env.RCTF_END_TIME) || Date.now() + 24 * 60 * 60 * 1000,
instanceType: process.env.RCTF_INSTANCE_TYPE || 'all' // enum: all, frontend, leaderboard
}

module.exports = config
3 changes: 0 additions & 3 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import express from 'express'
import helmet from 'helmet'
import { enableCORS, serveIndex } from './util'
import { init as uploadProviderInit } from './uploads'
import { startUpdater as leaderboardStartUpdater } from './leaderboard'
import api from './api'

leaderboardStartUpdater()

const app = express()

// Compression testing should be done in development only
Expand Down
16 changes: 13 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dotenv/config'

import config from '../config/server'
import migrate from './database/migrate'
import { init as uploadProviderInit } from './uploads'

(async () => {
if (config.database.migrate === 'before') {
Expand All @@ -13,8 +14,17 @@ import migrate from './database/migrate'
throw new Error('migration config not recognized')
}

const PORT = process.env.PORT || 3000
if (config.instanceType === 'frontend' || config.instanceType === 'all') {
const port = process.env.PORT || 3000

const { default: app } = await import('./app')
app.listen(PORT, () => console.log(`Started server at port ${PORT}`))
const { default: app } = await import('./app')
app.listen(port, () => console.log(`Started server at port ${port}`))
} else {
uploadProviderInit(null)
}
if (config.instanceType === 'leaderboard' || config.instanceType === 'all') {
const { startUpdater } = await import('./leaderboard')
startUpdater()
console.log('Started leaderboard updater')
}
})()
5 changes: 5 additions & 0 deletions server/providers/uploads/dummy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Provider } from '../../../uploads/types'

export default class DummyProvider implements Provider {
upload = async (): Promise<string> => ''
}
5 changes: 3 additions & 2 deletions server/uploads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { Provider } from './types'

let provider: Provider = null

export const init = (app: express.Application): void => {
const ProviderClass = require(path.join('../providers', config.uploadProvider.name)).default
export const init = (app: express.Application | null): void => {
const name = app === null ? 'uploads/dummy' : config.uploadProvider.name
const ProviderClass = require(path.join('../providers', name)).default
provider = new ProviderClass(config.uploadProvider.options, app)
}

Expand Down