-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.coffee
75 lines (58 loc) · 1.98 KB
/
server.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
coffee = require "coffee-script"
body_parser = require "body-parser"
method_override = require "method-override"
logger = require "morgan"
uglify = require "uglify-js"
fs = require "fs"
express = require "express"
stylus = require "stylus"
# parse all songs
songs = []
# define a parser
global.$$ = (song) ->
API =
header: (info) ->
# parse seconds count to user-friendly "m:ss" string
seconds = info.length
info.length = "#{Math.floor(seconds/60)}:#{if seconds%60 < 10 then '0' else ''}#{seconds%60}"
# store song info in songs list
songs.push info
# need to be implemented on the client-side
line: () -> 0
wait: () -> 0
song.call API
# read song files
# and compile them all to a single JS file
files = fs.readdirSync "songs/"
js = ""
for file in files
js += coffee.compile (fs.readFileSync "./songs/#{file}", "utf8"), bare: true
require("./songs/#{file}")
fs.writeFileSync "#{__dirname}/static/scripts/songs.js",
(uglify.minify js).code
esenin_js = coffee.compile (fs.readFileSync "./static/scripts/esenin.coffee", "utf8"), bare: true
fs.writeFileSync "./static/scripts/esenin.js",
(uglify.minify esenin_js).code
# configure express
app = express()
app.set "views", "#{__dirname}/views"
app.set "view engine", "pug"
app.use body_parser.urlencoded extended: true
app.use body_parser.json()
app.use method_override()
app.use logger "dev"
app.use stylus.middleware
src: __dirname
dest: __dirname
compile: (str, path) ->
stylus(str)
.define("url", stylus.url( paths: [__dirname] ))
.set("filename", path)
.set("compress", true)
app.use "/static", express.static "#{__dirname}/static"
app.get "/", (req, res) ->
res.render "index",
songs: songs
port = 2109
console.log "Listening on port #{port}"
app.listen port