Commit 168aa2b8 authored by Leo Iannacone's avatar Leo Iannacone

code style on debomatic-webui main file

parent d5b34635
"use strict"
###
Module dependencies.
###
http = require("http")
express = require("express")
app = module.exports = require("express")()
server = require("http").createServer(app)
io = require("socket.io")(server)
serve_static = require("serve-static")
serve_index = require("serve-index")
errorhandler = require("errorhandler")
routes = require("./routes")
config = require("./lib/config")
utils = require("./lib/utils")
Client = require("./lib/client")
Debomatic = require("./lib/debomatic")
app = module.exports = express()
server = http.createServer(app)
io = require("socket.io")(server)
# error handler setup
env = process.env.NODE_ENV or "development"
if "development" is env
app.use errorhandler(
dumpExceptions: true
showStack: true
)
else app.use errorhandler() if "production" is env
app.set "views", __dirname + "/views"
app.set "view engine", "ejs"
if env is "development"
app.use(errorhandler({dumpExceptions: true, showStack: true}))
else
app.use(errorhandler())
# the views
app.set("views", __dirname + "/views")
app.set("view engine", "ejs")
# index page
app.get "/", routes.index
app.get("/", routes.index)
# distibution page
app.get config.routes.distribution, routes.distribution
app.get(config.routes.distribution, routes.distribution)
# parefernces page
# preferences page
if config.routes.preferences
app.get config.routes.preferences, routes.preferences
app.get(config.routes.preferences, routes.preferences)
# commands page
app.get config.routes.commands, routes.commands if config.routes.commands
if config.routes.commands
app.get(config.routes.commands, routes.commands)
# debomatic static page
if config.routes.debomatic
app.all config.routes.debomatic + "*", (req, res, next) ->
# send 403 status when users want to browse the chroots:
# - unstable/unstable
# - unstable/build/*
# this prevents system crashes
base = config.routes.debomatic
base += (if base[base.length - 1] isnt "/" then "/" else "") # append /
base += "/" if base[base.length - 1] isnt "/" # append /
match = req.url.replace(base, "").split("/")
match.pop() if match[match.length - 1] is ""
......@@ -60,45 +62,33 @@ if config.routes.debomatic
next()
return
app.use config.routes.debomatic, serve_static(config.debomatic.path)
app.use(config.routes.debomatic, serve_static(config.debomatic.path))
app.use(config.routes.debomatic, serve_index(config.debomatic.path,
{view: "details", icons: true}))
# serve stylesheet-javascript
app.use serve_static(__dirname + "/public")
app.use(serve_static(__dirname + "/public"))
# serve dsc files as octet-stream
serve_static.mime.define "application/octet-stream": ["dsc"]
serve_static.mime.define("application/octet-stream": ["dsc"])
# Listening
server.listen config.port, config.host, null, (err) ->
# Checking nodejs with sudo:
# Find out which user used sudo through the environment variable
# and set his user id
uid = parseInt(process.env.SUDO_UID)
if uid
console.log "Please do not run nodejs with sudo. " +
"Changing user to %d", uid
process.setgid uid
process.setuid uid
debomatic = new Debomatic(io.sockets)
debomatic.start()
io.sockets.on "connection", (socket) ->
client = new Client(socket)
client.start()
client.send_status debomatic.status
client.send_status(debomatic.status)
client.send_status_debomatic(debomatic.running)
client.send_distributions(debomatic.distributions)
return
console.log "Debomatic-webui listening on %s:%d in %s mode",
server.address().address,
server.address().port,
app.settings.env
return
server.on "error", (e) ->
if e.code is "EADDRINUSE"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment