Created
October 11, 2013 00:26
-
-
Save jeffthink/6927836 to your computer and use it in GitHub Desktop.
Express.static in heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var express = require("express"); | |
var app = express(); | |
//use logger | |
app.use(express.logger()); | |
//compress with gzip/deflate | |
app.use(express.compress()); | |
//serve up static pages with max-age headers of 1 day | |
app.use(express.static(path.join(__dirname, '../app'), { maxAge: 86400000 })); | |
//body parsing middleware (for json, urlencoded, and multipart responses) | |
app.use(express.bodyParser()); | |
//handle any errors | |
app.use(function(err, req, res, next){ | |
console.error(err.stack); | |
res.send(500, 'Something broke!'); | |
}); | |
// Render the app | |
app.get('/', function(req, res) { | |
res.sendfile(path.join(__dirname, '../app/index.html')); | |
}); | |
//start server | |
var port = process.env.PORT || 5000; | |
app.listen(port, function() { | |
console.log("Listening on " + port); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<link rel="stylesheet" href="/css/base.css"/> | |
<link rel="stylesheet" href="/css/sub/sub.css"/> | |
<script type="text/javascript" src="/scripts/base.js"></script> | |
<script type="text/javascript" src="/scripts/sub/sub.js"></script> | |
</head> | |
<body> | |
<img src="/img/base.jpg" /> | |
<img src="/img/sub/sub.jpg" /> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my-repo", | |
"version": "0.0.1", | |
"scripts": { | |
"start": "node server/app.js" | |
}, | |
"dependencies": { | |
"express": "3.4" | |
}, | |
"devDependencies": {}, | |
"engines": { | |
"node": "0.10.x", | |
"npm": "1.2.30" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node server/app.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment