-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
63 lines (48 loc) · 1.39 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
express = require('express')
http = require('http')
path = require('path')
fs = require('fs')
_ = require('lodash')
app = express()
# all environments
app.set "port", process.env.PORT or 5000
app.set "views", __dirname
# development only
app.use express.errorHandler() if "development" is app.get("env")
app.use express.favicon()
app.use express.logger("dev")
app.use express.json()
app.use express.urlencoded()
app.use app.router
app.use express.static(path.join(__dirname, "build"))
# Load index.html
app.get "/", (req, res) ->
res.sendfile('./index.html')
getTableData = (req, res) ->
table = req.route.path.split('/')[2]
knex(table).select("*").then (data) ->
res.send(data)
tables = [
'route1'
'route2'
]
# Define routes based on tables array
# _.each tables, (table) =>
# app.get("/api/#{table}", getTableData)
# Super-hackable example user auth where I just making sure the email is in the DB
# app.post "/api/users", (req, res) ->
# console.log('email: ', req.body.email)
# knex('users')
# .where(email: req.body.email)
# .then( (data) ->
# if _.isEmpty(data)
# res.send(false)
# else
# d = data[0]
# d.comments = undefined
# console.log('user:', d)
# res.send(d)
# )
# Start server
http.createServer(app).listen app.get("port"), ->
console.log "Express server listening on port " + app.get("port")