From 9f3b46ade1b180de56b3fb118c45e8cf2f0a2f84 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 23 Feb 2016 23:10:38 +0100 Subject: [PATCH] Add livereload support and proxy to API. --- Gruntfile.js | 1 + grunt-config/connect.js | 32 ++++++++++++++++++++++++++++++++ grunt-config/watch.js | 10 ++++++++++ package.json | 3 +++ 4 files changed, 46 insertions(+) create mode 100644 grunt-config/connect.js diff --git a/Gruntfile.js b/Gruntfile.js index a5550d2..9d310ea 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -55,6 +55,7 @@ module.exports = function(grunt) { grunt.registerTask('serve', [ 'dev', 'bgShell:runserver', + 'connect:livereload', 'watch' ]); diff --git a/grunt-config/connect.js b/grunt-config/connect.js new file mode 100644 index 0000000..a6c3574 --- /dev/null +++ b/grunt-config/connect.js @@ -0,0 +1,32 @@ +'use strict'; + +module.exports = { + options: { + port: 5001, + hostname: 'localhost', + base: '<%= accountant.frontend.src %>', + apiUrl: 'http://localhost:5000/api/', + livereload: 1337, + }, + proxies: [{ + context: '/api', + host: '127.0.0.1', + port: 5000, + https: false + }], + livereload: { + options: { + //open: true, + middleware: function(connect, options, middlewares) { + var connectLogger = require('connect-logger'); + var connectProxy = require('connect-proxy-layer'); + var proxy = connectProxy(options.apiUrl); + + return [ + connectLogger(), + connect().use('/api', proxy), + ].concat(middlewares); + } + } + } +}; diff --git a/grunt-config/watch.js b/grunt-config/watch.js index 8f4cc90..3955edc 100644 --- a/grunt-config/watch.js +++ b/grunt-config/watch.js @@ -26,6 +26,16 @@ module.exports = { gruntfile: { files: ['Gruntfile.js', 'grunt-config/*.js'] }, + livereload: { + options: { + livereload: '<%= connect.options.livereload %>' + }, + files: [ + '<%= accountant.frontend.src %>/{,*/}*.html', + '<%= accountant.frontend.src %>/js/*.js', + '<%= accountant.frontend.src %>/css/*.css' + ] + }, requirements: { files: ['requirements.txt'], tasks: ['shell:pip_install'] diff --git a/package.json b/package.json index 4a8c6f5..2a9262a 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,13 @@ "repository": "https://git.lahouze.org/xals/accountant", "license": "AGPL-1.0", "devDependencies": { + "connect-logger": "0.0.1", + "connect-proxy-layer": "^0.1.2", "grunt": "^0.4.5", "grunt-bg-shell": "^2.3.1", "grunt-contrib-clean": "^1.0.0", "grunt-contrib-concat": "^0.5.1", + "grunt-contrib-connect": "^0.11.2", "grunt-contrib-cssmin": "^0.14.0", "grunt-contrib-jshint": "^1.0.0", "grunt-contrib-uglify": "^0.11.1",