Last active
October 5, 2015 13:30
-
-
Save gaboesquivel/d493a8fe91c4836de41f to your computer and use it in GitHub Desktop.
how to publish a site built with generator-gulp-webapp to heroku
This file contains 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
// 1. change dist dir to dist/public in the gulpfile | |
// 2. update .gitignore file too, dist --> dist/public | |
// 3. create dist/server.js | |
var express = require('express') | |
var serveStatic = require('serve-static') | |
var compression = require('compression') | |
var port = process.env.PORT || 3000; | |
var domain = process.env.DOMAIN; | |
function ensureDomain(req, res, next){ | |
if(!domain || req.hostname === domain){ | |
// OK, continue | |
return next(); | |
}; | |
res.redirect('http://'+domain+req.url); // handle port numbers if you need non defaults | |
}; | |
var app = express() | |
app.all('*', ensureDomain); // at top of routing calls | |
app.use(compression()) | |
app.use(serveStatic(__dirname + '/public', {'extensions': ['html']})) | |
app.listen(port, function(){ | |
console.log('server running ...'); | |
}); | |
// 4. create dist/package.json | |
{ | |
"name": "mysite", | |
"version": "0.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"engines":{ | |
"node": "0.12.x" | |
}, | |
"dependencies": { | |
"compression": "^1.4.4", | |
"express": "^4.12.3", | |
"serve-static": "^1.9.2" | |
} | |
} | |
// 5. run gulp build | |
// 6. for deploying push dist folder to heroku using git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment