Skip to content

Instantly share code, notes, and snippets.

@kieran
Created December 13, 2015 21:09
Show Gist options
  • Save kieran/acebdf4ffa58fd86994c to your computer and use it in GitHub Desktop.
Save kieran/acebdf4ffa58fd86994c to your computer and use it in GitHub Desktop.
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>MyApp</title>
<meta name="title" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<!--[if lt IE 8]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="app">
<p class="text-center lead" style="margin-top: 200px">
Loading ...
</p>
</div>
<script type="text/javascript" src="vendor.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
process.env.HOST ?= '0.0.0.0'
process.env.PORT ?= 4000
process.env.WEB_HOST ?= 'localhost'
process.env.WEB_PORT ?= 3000
http = require 'http'
express = require 'express'
path = require 'path'
# cross domain headers
allowCrossDomain = (req, res, next)->
res.header 'Access-Control-Allow-Origin', '*'
res.header 'Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'
res.header 'Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'
# intercept OPTIONS method
if 'OPTIONS' == req.method
res.send 200
else
next()
app = express()
app.use express.static "./dist"
# use webpack middleware in development
unless process.env.NODE_ENV is 'production'
webpackdm = require 'webpack-dev-middleware'
webpack = require 'webpack'
app.use webpackdm webpack(require('./webpack.config.coffee')), stats: colors: true
app.use allowCrossDomain
# index.html fallback for any 404 route
unless process.env.NODE_ENV is 'production'
app.get '*', (req, res)->
res.sendFile path.join __dirname, './app/index.html'
# create the http server
server = http.createServer app
# release the kraken!
console.log "NEW COAT OF PAINT on #{process.env.HOST}:#{process.env.PORT}"
server.listen process.env.PORT, process.env.HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment