/
server.coffee
35 lines (27 loc) · 1.37 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
# This is a helper file that is used to launch a local server used for development of your app.
express = require 'express'
fs = require 'fs'
app = express()
# By default the server launches at `http://localhost:8000`, you can change it in the
# [`grunt/express-server.coffee`](express-server.html) file config.
port = process.env.PORT || 8000
# The server is also configured to allow CORS.
app.use (request, response, next) ->
response.header 'Access-Control-Allow-Origin', '*'
response.header 'Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'
response.header 'Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'
next()
# This is for debugging purposes, it allows you to view the raw files as plain text.
app.use (request, response, next) ->
if /\.(coffee|jade|sass|scss|styl|less)$/.test request.url
response.set 'Content-Type', 'text/plain'
next()
# The server will server everything in the root folder it's launched from. If you want to test the built files
# then you can do a quick and sneaky change here to point it to the `/build` directory instead.
app.use '/', express.static "#{__dirname}/"
app.options '*', (request, response, next) ->
response.send 200
app.all '*', (request, response, next) ->
response.sendfile "#{__dirname}/index.html"
app.listen port, () ->
console.log "Listening on port: #{port}"