-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.coffee
76 lines (61 loc) · 1.77 KB
/
app.coffee
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
express = require 'express'
app = express()
app.use express.bodyParser()
app.use require('connect-assets')()
http = require 'http'
server = http.createServer app
io = require('socket.io').listen server
io.set "log level", 1
_ = require "underscore"
# Acadock classes
Container = require './lib/models/container'
urlHelper = require './lib/helpers/urlHelper'
websocket = require './lib/websocket'
app.get '/', (req, res) ->
console.log("List all containers")
Container.findAll (containers, err) ->
if !err
res.render 'index.jade', { containers: containers }
else
res.status 400
res.send(err)
app.get '/containers/new', (req, res) ->
console.log("Create container")
res.render 'containers/new.jade'
app.post '/containers/create', (req,res) ->
console.log("Create container")
if !req.body.container
res.status 422
res.end()
else
Container.create req.body.container, (container, err) ->
if container
res.send(container)
else
res.status(422)
res.end()
app.delete '/containers/:name', (req, res) ->
console.log("Delete Container")
Container.destroy req.params.name, (err) ->
if !err
res.status(200)
res.end()
else
res.status(422)
res.end()
app.get '/containers/:name', (req, res) ->
console.log("Inspect container")
websocket io, req.params.name
Container.find req.params.name, (container, err) ->
if !err
res.render 'containers/show.jade', {container: container, _: _}
else
res.status 422
res.end(err)
app.get '/containers/:name/attach', (req, res) ->
console.log("Attach container")
Container.attach req.params.name, res
app.all "*", (req, res) ->
console.log(req.method + " " + req.path)
res.end()
server.listen(process.env.PORT || 3000)