Skip to content

Commit 19f75dc

Browse files
committed
Merge branch 'master' into develop
Adds static host functionality to develop branch
2 parents d686565 + 37cb63b commit 19f75dc

File tree

16 files changed

+197
-35
lines changed

16 files changed

+197
-35
lines changed

backend/migrations/20180618015850_initial.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ exports.up = function (knex/*, Promise*/) {
6969
table.json('domain_names').notNull();
7070
table.string('forward_ip').notNull();
7171
table.integer('forward_port').notNull().unsigned();
72+
table.string('root_dir').notNull();
73+
table.string('index_file').notNull();
74+
table.integer('static').notNull().unsigned().defaultTo(0);
7275
table.integer('access_list_id').notNull().unsigned().defaultTo(0);
7376
table.integer('certificate_id').notNull().unsigned().defaultTo(0);
7477
table.integer('ssl_forced').notNull().unsigned().defaultTo(0);

backend/schema/definitions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@
222222
"description": "Should we cache assets",
223223
"example": true,
224224
"type": "boolean"
225+
},
226+
"static": {
227+
"description": "Should the proxy point to static files",
228+
"example": true,
229+
"type": "boolean"
225230
}
226231
}
227232
}

backend/schema/endpoints/proxy-hosts.json

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@
2424
},
2525
"forward_host": {
2626
"type": "string",
27-
"minLength": 1,
27+
"minLength": 0,
2828
"maxLength": 255
2929
},
3030
"forward_port": {
3131
"type": "integer",
32-
"minimum": 1,
32+
"minimum": 0,
3333
"maximum": 65535
3434
},
35+
"root_dir": {
36+
"type": "string",
37+
"minLength": 0,
38+
},
39+
"index_file": {
40+
"type": "string",
41+
"minLength": 0,
42+
},
3543
"certificate_id": {
3644
"$ref": "../definitions.json#/definitions/certificate_id"
3745
},
@@ -53,6 +61,9 @@
5361
"caching_enabled": {
5462
"$ref": "../definitions.json#/definitions/caching_enabled"
5563
},
64+
"static": {
65+
"$ref": "../definitions.json#/definitions/static"
66+
},
5667
"allow_websocket_upgrade": {
5768
"description": "Allow Websocket Upgrade for all paths",
5869
"example": true,
@@ -76,10 +87,7 @@
7687
"items": {
7788
"type": "object",
7889
"required": [
79-
"forward_scheme",
80-
"forward_host",
81-
"forward_port",
82-
"path"
90+
"forward_scheme"
8391
],
8492
"additionalProperties": false,
8593
"properties": {
@@ -99,6 +107,15 @@
99107
"forward_port": {
100108
"$ref": "#/definitions/forward_port"
101109
},
110+
"root_dir": {
111+
"$ref": "#/definitions/root_dir"
112+
},
113+
"index_file": {
114+
"$ref": "#/definitions/index_file"
115+
},
116+
"static": {
117+
"$ref": "#/definitions/static"
118+
},
102119
"forward_path": {
103120
"type": "string"
104121
},
@@ -131,6 +148,12 @@
131148
"forward_port": {
132149
"$ref": "#/definitions/forward_port"
133150
},
151+
"root_dir": {
152+
"$ref": "#/definitions/root_dir"
153+
},
154+
"index_file": {
155+
"$ref": "#/definitions/index_file"
156+
},
134157
"certificate_id": {
135158
"$ref": "#/definitions/certificate_id"
136159
},
@@ -152,6 +175,9 @@
152175
"caching_enabled": {
153176
"$ref": "#/definitions/caching_enabled"
154177
},
178+
"static": {
179+
"$ref": "#/definitions/static"
180+
},
155181
"allow_websocket_upgrade": {
156182
"$ref": "#/definitions/allow_websocket_upgrade"
157183
},
@@ -204,9 +230,7 @@
204230
"additionalProperties": false,
205231
"required": [
206232
"domain_names",
207-
"forward_scheme",
208-
"forward_host",
209-
"forward_port"
233+
"forward_scheme"
210234
],
211235
"properties": {
212236
"domain_names": {
@@ -221,6 +245,12 @@
221245
"forward_port": {
222246
"$ref": "#/definitions/forward_port"
223247
},
248+
"root_dir": {
249+
"$ref": "#/definitions/root_dir"
250+
},
251+
"index_file": {
252+
"$ref": "#/definitions/index_file"
253+
},
224254
"certificate_id": {
225255
"$ref": "#/definitions/certificate_id"
226256
},
@@ -242,6 +272,9 @@
242272
"caching_enabled": {
243273
"$ref": "#/definitions/caching_enabled"
244274
},
275+
"static": {
276+
"$ref": "#/definitions/static"
277+
},
245278
"allow_websocket_upgrade": {
246279
"$ref": "#/definitions/allow_websocket_upgrade"
247280
},
@@ -294,6 +327,12 @@
294327
"forward_port": {
295328
"$ref": "#/definitions/forward_port"
296329
},
330+
"root_dir": {
331+
"$ref": "#/definitions/root_dir"
332+
},
333+
"index_file": {
334+
"$ref": "#/definitions/index_file"
335+
},
297336
"certificate_id": {
298337
"$ref": "#/definitions/certificate_id"
299338
},
@@ -315,6 +354,9 @@
315354
"caching_enabled": {
316355
"$ref": "#/definitions/caching_enabled"
317356
},
357+
"static": {
358+
"$ref": "#/definitions/static"
359+
},
318360
"allow_websocket_upgrade": {
319361
"$ref": "#/definitions/allow_websocket_upgrade"
320362
},

backend/templates/_listen.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
{% endif %}
1414
{% endif %}
1515
server_name {{ domain_names | join: " " }};
16+
{% if static == 1 or static == true %}
17+
root {{ root_dir }};
18+
index {{ index_file }};
19+
{% endif %}
20+

backend/templates/_location.conf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
___location {{ path }} {
2-
proxy_set_header Host $host;
3-
proxy_set_header X-Forwarded-Scheme $scheme;
4-
proxy_set_header X-Forwarded-Proto $scheme;
5-
proxy_set_header X-Forwarded-For $remote_addr;
6-
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};
2+
3+
{% if static == 0 or static == false %}
4+
proxy_set_header Host $host;
5+
proxy_set_header X-Forwarded-Scheme $scheme;
6+
proxy_set_header X-Forwarded-Proto $scheme;
7+
proxy_set_header X-Forwarded-For $remote_addr;
8+
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};
9+
{% else %}
10+
alias {{ root_dir }}/$1;
11+
try_files $uri /{{ index_file }} =200;
12+
{% endif %}
13+
714
{{ advanced_config }}
815
}
916

backend/templates/default.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ server {
2424

2525
{%- if value == "html" %}
2626
root /data/nginx/default_www;
27+
# root /var/www/test2;
2728
___location / {
2829
try_files $uri /index.html;
2930
}

backend/templates/proxy_host.conf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ server {
4848
proxy_http_version 1.1;
4949
{% endif %}
5050

51-
# Proxy!
52-
include conf.d/include/proxy.conf;
51+
{% if static == 1 or static == true %}
52+
alias {{ root_dir }}/$1;
53+
try_files $uri /{{index_file}} =200;
54+
{% else %}
55+
# Proxy!
56+
include conf.d/include/proxy.conf;
57+
58+
{% endif %}
5359
}
5460
{% endif %}
5561

frontend/js/app/nginx/proxy/form.ejs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
<div class="col-sm-3 col-md-3">
3636
<div class="form-group">
37-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %><span class="form-required">*</span></label>
37+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %></label>
3838
<select name="forward_scheme" class="form-control custom-select" placeholder="http">
3939
<option value="http" <%- forward_scheme === 'http' ? 'selected' : '' %>>http</option>
4040
<option value="https" <%- forward_scheme === 'https' ? 'selected' : '' %>>https</option>
@@ -43,14 +43,26 @@
4343
</div>
4444
<div class="col-sm-5 col-md-5">
4545
<div class="form-group">
46-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><span class="form-required">*</span></label>
47-
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" autocomplete="off" maxlength="255" required>
46+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><% if (!static) { %> <span class="form-required">*</span><% } %></label>
47+
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" <%- !static ? 'required' : '' %> autocomplete="off" maxlength="255">
4848
</div>
4949
</div>
5050
<div class="col-sm-4 col-md-4">
5151
<div class="form-group">
52-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <span class="form-required">*</span></label>
53-
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" required>
52+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %><% if (!static) { %> <span class="form-required">*</span><% } %> </label>
53+
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" <%- !static ? 'required' : '' %>>
54+
</div>
55+
</div>
56+
<div class="col-sm-5 col-md-5">
57+
<div class="form-group">
58+
<label class="form-label"><%- i18n('proxy-hosts', 'root-dir') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
59+
<input type="text" name="root_dir" class="form-control text-monospace" placeholder="" value="<%- root_dir %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
60+
</div>
61+
</div>
62+
<div class="col-sm-5 col-md-5">
63+
<div class="form-group">
64+
<label class="form-label"><%- i18n('proxy-hosts', 'index-file') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
65+
<input type="text" name="index_file" class="form-control text-monospace" placeholder="" value="<%- index_file %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
5466
</div>
5567
</div>
5668
<div class="col-sm-6 col-md-6">
@@ -80,6 +92,15 @@
8092
</label>
8193
</div>
8294
</div>
95+
<div class="col-sm-12 col-md-12">
96+
<div class="form-group">
97+
<label class="custom-switch">
98+
<input type="checkbox" class="custom-switch-input static-checkbox" name="static" value="1"<%- static ? ' checked' : '' %>>
99+
<span class="custom-switch-indicator"></span>
100+
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'static') %></span>
101+
</label>
102+
</div>
103+
</div>
83104

84105
<div class="col-sm-12 col-md-12">
85106
<div class="form-group">

frontend/js/app/nginx/proxy/form.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = Mn.View.extend({
2222
form: 'form',
2323
domain_names: 'input[name="domain_names"]',
2424
forward_host: 'input[name="forward_host"]',
25+
root_dir: 'input[name="root_dir"]',
26+
index_file: 'input[name="index_file"]',
27+
static: 'input[type="checkbox"].static-checkbox',
2528
buttons: '.modal-footer button',
2629
cancel: 'button.cancel',
2730
save: 'button.save',
@@ -42,6 +45,20 @@ module.exports = Mn.View.extend({
4245
},
4346

4447
events: {
48+
49+
'click @ui.static': function(e){
50+
51+
const map = {};
52+
53+
let value = e.target.value
54+
if(e.target.type == 'checkbox') value = e.target.checked
55+
map[e.target.name] = value
56+
this.model.set(map);
57+
58+
setTimeout(this.render.bind(this), 300)
59+
60+
},
61+
4562
'change @ui.certificate_select': function () {
4663
let id = this.ui.certificate_select.val();
4764
if (id === 'new') {
@@ -128,7 +145,8 @@ module.exports = Mn.View.extend({
128145
data.hsts_enabled = !!data.hsts_enabled;
129146
data.hsts_subdomains = !!data.hsts_subdomains;
130147
data.ssl_forced = !!data.ssl_forced;
131-
148+
data.static = !!data.static;
149+
132150
if (typeof data.domain_names === 'string' && data.domain_names) {
133151
data.domain_names = data.domain_names.split(',');
134152
}

frontend/js/app/nginx/proxy/list/item.ejs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
</div>
2424
</td>
2525
<td>
26-
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
26+
<!-- <div> <%- static %> </div> -->
27+
<% if (!static) { %>
28+
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
29+
<% } else { %>
30+
<div class="text-monospace"><%- root_dir %></div>
31+
<div class="text-monospace"><%- index_file %></div>
32+
<% } %>
2733
</td>
2834
<td>
2935
<div><%- certificate && certificate_id ? i18n('ssl', certificate.provider) : i18n('ssl', 'none') %></div>

0 commit comments

Comments
 (0)