From 3af52737d41d2c645e9ad7888431deee63a3bd44 Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Sun, 22 Feb 2015 13:28:21 +0100 Subject: [PATCH] fixed grunt dev so pushstate routes now work ( 404 -> index.html) --- front-ui/Gruntfile.js | 80 +++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/front-ui/Gruntfile.js b/front-ui/Gruntfile.js index 932e746..a0b4af9 100644 --- a/front-ui/Gruntfile.js +++ b/front-ui/Gruntfile.js @@ -15,15 +15,24 @@ module.exports = function(grunt) { } }, - watch: { - files: ['build/ribica.bundle.js', 'app/css/*.css'], - tasks: ['config-dev', 'concat:css', 'concat:js'] + watch: { + files: ['build/ribica.bundle.js', 'app/css/*.css'], + tasks: ['config-dev', 'concat:css', 'concat:js'] }, connect: { server: { options: { port: 3001, - base: 'build' + base: 'build', + middleware: function(connect, options) { + return [ + function(req, res) { + var filename = 'build/' + req.url; + if ((filename === 'build//') || !grunt.file.exists(filename)) filename = 'build/index.html'; + res.end(grunt.file.read(filename)); + } + ]; + }, } } }, @@ -35,39 +44,42 @@ module.exports = function(grunt) { } }, config: { - dev: { - options: { - variables: { - apiEndpoint: 'http://localhost:4567' - } - } - }, - prod: { - options: { - variables: { - apiEndpoint: '/api' - } - } - } + dev: { + options: { + variables: { + apiEndpoint: 'http://localhost:4567' + } + } + }, + prod: { + options: { + variables: { + apiEndpoint: '/api' + } + } + } }, replace: { - dist: { - options: { - variables: { - 'apiEndpoint': '<%= grunt.config.get("apiEndpoint") %>' + dist: { + options: { + variables: { + 'apiEndpoint': '<%= grunt.config.get("apiEndpoint") %>' + }, + force: true + }, + files: [{ + expand: true, + flatten: true, + src: ['build/ribica.bundle.js'], + dest: 'build/' + }] + } }, - force: true - }, - files: [ - {expand: true, flatten: true, src: ['build/ribica.bundle.js'], dest: 'build/'} - ] - } -}, concat: { css: { src: [ - 'node_modules/bootstrap/dist/css/bootstrap.min.css', - 'app/css/*.css' + 'node_modules/bootstrap/dist/css/bootstrap.min.css', + 'app/css/*.css' ], dest: 'build/ribica.css' @@ -87,12 +99,12 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-config'); grunt.loadNpmTasks('grunt-replace'); - + grunt.registerTask('default', []); grunt.registerTask('config-dev', ['config:dev', 'replace']); grunt.registerTask('config-prod', ['config:prod', 'replace']); - grunt.registerTask('dev', ['browserify', 'config-dev','concat:css', 'concat:js', 'connect:server:keepalive']); + grunt.registerTask('dev', ['browserify', 'config-dev', 'concat:css', 'concat:js', 'connect:server:keepalive']); grunt.registerTask('build', ['browserify', 'config-prod', 'concat:css', 'concat:js']); -}; +}; \ No newline at end of file