-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (41 loc) · 1.15 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const r1 = require('./runner-01')
const r2 = require('./runner-02')
const port = 6969
const app = express()
// middlewares
app.use(morgan('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
// routes
app.get('/', (req, res) => res.send('OKAY!'))
app.post('/run/:name', async (req, res) => {
const {id, student_repo, tester_repo: mentor_repo} = req.body
const {name} = req.params
const secret = req.headers['x-secret'];
console.log('id', id)
console.log('student_repo', student_repo)
console.log('mentor_repo', mentor_repo)
console.log('secret', secret)
try {
switch(name) {
case 'node-stdout':
r2.start(id, secret, student_repo, mentor_repo)
break
case 'node-http':
r1.start(id, secret, student_repo, mentor_repo)
break
default:
throw new Error('Runner is not found!')
}
return res.json({success: true})
} catch(err) {
res.json({success: false, reason: err.message})
}
})
// server start
app.listen(port, (err) => {
if (!err) console.log('Server is listening on', port)
})