forked from mart2967/testProject2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.coffee
69 lines (58 loc) · 2.16 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
#/home/mart2967/mongodb/bin/mongod --dbpath ~/WebstormProjects/testProject2/db/ --smallfiles
express = require 'express'
routes = require './routes'
classes = require './routes/classes'
gpa = require './routes/gpa'
http = require 'http'
path = require 'path'
mongoose = require 'mongoose'
#models = require './schemas/schemas'
app = express()
#connect to database
# ./mongodb/bin/mongod --dbpath ~/WebstormProjects/testProject2/db/
mongoose.connect 'mongodb://localhost/test'
db = mongoose.connection
db.on 'error', console.error.bind(console, 'connection error:')
db.once 'open', ->
console.log 'DB connection opened'
#nodeInfo = new models.Section {title: 'Node.js', link: 'http://nodejs.org/', body: 'blah', category: 'main'}
#nodeInfo.save()
#set main layout
app.set 'layout', 'layouts/main'
#expose templates to all views
app.set 'partials',
head: 'partials/head',
navbar: 'partials/navbar',
scripts: 'partials/scripts'
app.engine 'html', require('hogan-express')
app.enable 'view cache'
app.configure ->
app.set 'port', process.env.PORT or 3000
app.set 'views', __dirname + '/views'
app.set 'view engine', 'html'
app.use express.favicon()
app.use express.logger('dev')
app.use express.json()
app.use express.urlencoded()
app.use express.methodOverride()
app.use express.cookieParser('your secret here')
app.use express.session()
app.use app.router
#app.use(require('less-middleware')({ src: __dirname + '/public' }));
app.use express.static(path.join(__dirname, 'public'))
app.use express.static(path.join(__dirname, 'bower_components'))
app.configure 'development', ->
app.use express.errorHandler()
app.get '/', routes.index
app.get '/classes/:id', classes.getById
app.post '/classes', classes.create
app.get '/classes', classes.findAll
app.put '/classes/:id', classes.edit
#In theory these initialize and show the GPA data type held in the database. Right now it is a little messed up.
app.get '/gpa', routes.index
app.get '/gpa/:id', gpa.getByIdGPA
app.post '/gpa', gpa.create
app.get '/gpas', gpa.findAllGPA
app.put '/gpa/:id', gpa.edit
http.createServer(app).listen app.get('port'), ->
console.log 'Express server listening on port ' + app.get('port')