Last active
July 21, 2017 18:31
-
-
Save garrettmac/07b475ad1043ad9c79a49ee61963e497 to your computer and use it in GitHub Desktop.
simple gulp recipe to sever any projects dist folder with express & node. Just add these to a project then move any project you'd like to server at the root and rename the folder 'frontend' and you're done
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
'use strict'; | |
// simple express server | |
var express = require('express'); | |
var app = express(); | |
var router = express.Router(); | |
app.use(express.static('public')); | |
app.get('/', function(req, res) { | |
// res.sendfile('./public/index.html'); | |
}); | |
app.listen(5000); |
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
'use strict'; | |
var gulp = require('gulp'); | |
var browserSync = require('browser-sync'); | |
var nodemon = require('gulp-nodemon'); | |
gulp.task('default', ['browser-sync'], function () { | |
}); | |
gulp.task('browser-sync', ['nodemon'], function() { | |
browserSync.init(null, { | |
proxy: "http://localhost:5000", | |
files: ["public/**/*.*"], | |
port: 7000, | |
}); | |
}); | |
gulp.task('move', function(){ | |
gulp.src('frontend/dist/**/*', { base: 'frontend/dist/' }) | |
.pipe(gulp.dest('public')); | |
}); | |
gulp.task('nodemon',['move'], function (cb) { | |
var started = false; | |
return nodemon({ | |
script: 'app.js' | |
}).on('start', function () { | |
if (!started) { | |
cb(); | |
started = true; | |
} | |
}); | |
}); |
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
{ | |
"name": "dist-express-static-server", | |
"version": "0.0.1", | |
"private": true, | |
"dependencies": { | |
"body-parser": "*", | |
"error-handler": "^0.1.4", | |
"express": "*", | |
"gulp-express": "^0.3.5", | |
"html2jade": "^0.8.6", | |
"jade": "~0.31.2", | |
"method-override": "^1.0.0", | |
"morgan": "^1.0.0" | |
}, | |
"devDependencies": { | |
"http": "0.0.0", | |
"http-proxy-middleware": "^0.17.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment