Skip to content

Commit c8a79eb

Browse files
committed
refactor config dir
1 parent 4e85fab commit c8a79eb

File tree

10 files changed

+57
-14
lines changed

10 files changed

+57
-14
lines changed

config/config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
File renamed without changes.

config/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const developmentConfig = require('./development');
2+
const testConfig = require('./test');
3+
const productionConfig = require('./production');
4+
5+
const env = process.env.NODE_ENV || 'development';
6+
7+
if (env === 'test') {
8+
module.exports = testConfig;
9+
}
10+
else if(env === 'production') {
11+
module.exports = productionConfig;
12+
}
13+
else {
14+
module.exports = developmentConfig;
15+
}

config/production.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports = module.exports = {
2+
RUN: {
3+
TIMEOUT: process.env.RUN_TIMEOUT || 10000,
4+
},
5+
6+
// Domain/Host on which judge-api is hosted
7+
HOST: process.env.JUDGEAPI_HOST || 'localhost',
8+
// Port on which this app will run
9+
PORT: process.env.JUDGEAPI_PORT || 3737,
10+
11+
// Database config for a postgresql db (docker based or native)
12+
DB: {
13+
DATABASE: process.env.DB_NAME || 'judgeapi-dev',
14+
USERNAME: process.env.DB_USER || 'judgeapi',
15+
PASSWORD: process.env.DB_PASS || 'judgeapi',
16+
HOST: process.env.DB_HOST || 'localhost'
17+
},
18+
19+
// Rabbit MQ queue - the other end of which is attached
20+
// to judge-taskmaster
21+
AMQP: {
22+
USER: process.env.AMQP_USER || 'codingblocks',
23+
PASS: process.env.AMQP_PASS || 'codingblocks',
24+
HOST: process.env.AMQP_HOST || 'localhost',
25+
PORT: process.env.AMQP_PORT || 5672
26+
},
27+
28+
S3: {
29+
endpoint: process.env.S3_ENDPOINT || 'localhost',
30+
port: process.env.S3_PORT || 9000,
31+
ssl: process.env.S3_SSL || false,
32+
accessKey: process.env.S3_ACCESS_KEY || '',
33+
secretKey: process.env.S3_SECRET_KEY || '',
34+
bucket: process.env.S3_BUCKET || 'judge-submissions',
35+
region: process.env.S3_REGION || 'us-east-1'
36+
}
37+
}
File renamed without changes.

src/models/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33
import * as fs from 'fs'
44
import dbg = require('debug')
55

6-
const config = require('../../config/config');
6+
const config = require('../../config/index');
77
const basename = path.basename(module.filename);
88
const db: any = {}
99
const dbModel = {}

src/rabbitmq/jobqueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as amqp from 'amqplib/callback_api'
22
import { Channel, Connection } from 'amqplib/callback_api'
33
import { EventEmitter } from 'events'
44
const debug = require('debug')('judge:api:jobqueue')
5-
const config = require('../../config/config')
5+
const config = require('../../config/index')
66

77
export interface SubmissionJob {
88
id: number

src/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app from './server'
22
import * as debug from 'debug'
33
import DB from 'models'
44

5-
const config = require('../config/config')
5+
const config = require('../config/index')
66
const log = debug('judge:api')
77

88
DB.sequelize.sync({})

src/utils/s3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Minio = require('minio')
22
import v4 = require('uuid/v4')
33
import axios from 'axios'
44

5-
const config = require('../../config/config')
5+
const config = require('../../config/index')
66
const client = new Minio.Client({
77
endPoint: config.S3.endpoint,
88
port: +config.S3.port,

test/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as amqp from 'amqplib/callback_api';
22
import DB from "../../src/models";
3-
const config = require('../../config/config');
3+
const config = require('../../config/index');
44

55
const jobQ = 'job_queue'
66
const successQ = 'success_queue'

0 commit comments

Comments
 (0)