1 | import { Router, Request, Response, json } from 'express'
|
2 |
|
3 | const router = Router()
|
4 |
|
5 | import DockerCompiler from './DockerCompiler'
|
6 | import CachingUrlFetcher from './CachingUrlFetcher'
|
7 |
|
8 | const compiler = new DockerCompiler(new CachingUrlFetcher())
|
9 |
|
10 | router.use(json())
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function run (method: string) {
|
17 | return async (req: Request, res: Response) => {
|
18 | try {
|
19 |
|
20 | const node = await compiler[method](req.body)
|
21 | res.status(200).json(node)
|
22 | } catch (error) {
|
23 | res.status(500).write(error.stack)
|
24 | }
|
25 | }
|
26 | }
|
27 |
|
28 | router.put('/compile', run('compile'))
|
29 | router.put('/compile', run('execute'))
|
30 |
|
31 | export default router
|