-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (29 loc) · 1.01 KB
/
server.js
File metadata and controls
39 lines (29 loc) · 1.01 KB
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
import express from 'express'
import bodyParser from 'body-parser'
import path from 'path'
import executeNodejs from './executers/nodejs'
import executeRuby from './executers/ruby'
import { log } from './utils'
const app = express()
const PORT_NUMBER = process.env.PORT || 3000 /*global process*/
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
const executors = {
nodejs: executeNodejs,
ruby: executeRuby,
}
app.post('/api/run/:language', (req, res) => {
const { params: { language }, body: { userCode } } = req
if (!executors[language])
return res
.status(404)
.send('Unkown language specified')
executors[language](userCode)
.then(result => res.send(result))
.catch(log)
})
app.use(express.static(path.join(__dirname, 'client/public'))) /*global __dirname*/
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client/public', 'index.html')) /*global __dirname*/
})
app.listen(PORT_NUMBER, () => log(`Listening on port ${ PORT_NUMBER }`))