diff --git a/bin/migrate_create b/bin/migrate_create new file mode 100755 index 0000000..dc2b5ed --- /dev/null +++ b/bin/migrate_create @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ "$1" == "" ]; then + echo "Error: migrate name must be specified as first arg" + exit 1 +else + # Code path + SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + if hash realpath 2>/dev/null; then + export CODEBASE=$(realpath $SCRIPT_DIR/..) + elif hash grealpath 2>/dev/null; then + export CODEBASE=$(grealpath $SCRIPT_DIR/..) + else + export CODEBASE=$(readlink -e $SCRIPT_DIR/..) + fi + + if [ -z "$CODEBASE" ]; then + echo "Unable to determine absolute codebase directory" + exit 1 + fi + + cd "$CODEBASE" + + sudo /usr/local/bin/docker-compose run --rm --no-deps app node node_modules/knex/bin/cli.js migrate:make "$1" + exit $? +fi diff --git a/src/backend/migrations/20180929054513_websockets.js b/src/backend/migrations/20180929054513_websockets.js new file mode 100644 index 0000000..63698fa --- /dev/null +++ b/src/backend/migrations/20180929054513_websockets.js @@ -0,0 +1,37 @@ +'use strict'; + +const migrate_name = 'websockets'; +const logger = require('../logger').migrate; + +/** + * Migrate + * + * @see http://knexjs.org/#Schema + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.up = function (knex/*, Promise*/) { + logger.info('[' + migrate_name + '] Migrating Up...'); + + return knex.schema.table('proxy_host', function (proxy_host) { + proxy_host.integer('allow_websocket_upgrade').notNull().unsigned().defaultTo(0); + }) + .then(() => { + logger.info('[' + migrate_name + '] proxy_host Table altered'); + }); + +}; + +/** + * Undo Migrate + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.down = function (knex, Promise) { + logger.warn('[' + migrate_name + '] You can\'t migrate down this one.'); + return Promise.resolve(true); +}; \ No newline at end of file diff --git a/src/backend/schema/endpoints/proxy-hosts.json b/src/backend/schema/endpoints/proxy-hosts.json index bde76cd..11155f0 100644 --- a/src/backend/schema/endpoints/proxy-hosts.json +++ b/src/backend/schema/endpoints/proxy-hosts.json @@ -39,6 +39,11 @@ "caching_enabled": { "$ref": "../definitions.json#/definitions/caching_enabled" }, + "allow_websocket_upgrade": { + "description": "Allow Websocket Upgrade for all paths", + "example": true, + "type": "boolean" + }, "access_list_id": { "$ref": "../definitions.json#/definitions/access_list_id" }, @@ -80,6 +85,9 @@ "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, + "allow_websocket_upgrade": { + "$ref": "#/definitions/allow_websocket_upgrade" + }, "access_list_id": { "$ref": "#/definitions/access_list_id" }, @@ -148,6 +156,9 @@ "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, + "allow_websocket_upgrade": { + "$ref": "#/definitions/allow_websocket_upgrade" + }, "access_list_id": { "$ref": "#/definitions/access_list_id" }, @@ -200,6 +211,9 @@ "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, + "allow_websocket_upgrade": { + "$ref": "#/definitions/allow_websocket_upgrade" + }, "access_list_id": { "$ref": "#/definitions/access_list_id" }, diff --git a/src/backend/templates/proxy_host.conf b/src/backend/templates/proxy_host.conf index 17fc87c..da4dfdc 100644 --- a/src/backend/templates/proxy_host.conf +++ b/src/backend/templates/proxy_host.conf @@ -22,6 +22,12 @@ server { {% include "_forced_ssl.conf" %} + {% if allow_websocket_upgrade == 1 or allow_websocket_upgrade == true %} + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_http_version 1.1; + {% endif %} + # Proxy! include conf.d/include/proxy.conf; } diff --git a/src/frontend/js/app/nginx/proxy/form.ejs b/src/frontend/js/app/nginx/proxy/form.ejs index 0d0f45d..5a85cd8 100644 --- a/src/frontend/js/app/nginx/proxy/form.ejs +++ b/src/frontend/js/app/nginx/proxy/form.ejs @@ -50,6 +50,15 @@ +