File tree 5 files changed +31
-3
lines changed
frontend/js/app/nginx/proxy
5 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
1
const _ = require ( 'lodash' ) ;
4
2
const fs = require ( 'fs' ) ;
5
3
const Liquid = require ( 'liquidjs' ) ;
@@ -92,7 +90,7 @@ const internalNginx = {
92
90
} )
93
91
. then ( ( ) => {
94
92
return combined_meta ;
95
- } )
93
+ } ) ;
96
94
} ,
97
95
98
96
/**
@@ -146,13 +144,20 @@ const internalNginx = {
146
144
return new Promise ( ( resolve , reject ) => {
147
145
let template = null ;
148
146
let filename = internalNginx . getConfigName ( host_type , host . id ) ;
147
+
149
148
try {
150
149
template = fs . readFileSync ( __dirname + '/../templates/' + host_type + '.conf' , { encoding : 'utf8' } ) ;
151
150
} catch ( err ) {
152
151
reject ( new error . ConfigurationError ( err . message ) ) ;
153
152
return ;
154
153
}
155
154
155
+ // Manipulate the data a bit before sending it to the template
156
+ host . use_default_location = true ;
157
+ if ( typeof host . advanced_config !== 'undefined' && host . advanced_config ) {
158
+ host . use_default_location = ! internalNginx . advancedConfigHasDefaultLocation ( host . advanced_config ) ;
159
+ }
160
+
156
161
renderEngine
157
162
. parseAndRender ( template , host )
158
163
. then ( config_text => {
@@ -312,6 +317,14 @@ const internalNginx = {
312
317
} ) ;
313
318
314
319
return Promise . all ( promises ) ;
320
+ } ,
321
+
322
+ /**
323
+ * @param {string } config
324
+ * @returns {boolean }
325
+ */
326
+ advancedConfigHasDefaultLocation : function ( config ) {
327
+ return ! ! config . match ( / ^ (?: .* ; ) ? \s * ?l o c a t i o n \s * ?\/ \s * ?{ / im) ;
315
328
}
316
329
} ;
317
330
Original file line number Diff line number Diff line change @@ -10,10 +10,13 @@ server {
10
10
11
11
{{ advanced_config }}
12
12
13
+ {% if use_default_location %}
13
14
location / {
14
15
{% include "_forced_ssl.conf" %}
15
16
{% include "_hsts.conf" %}
16
17
return 404;
17
18
}
19
+ {% endif %}
20
+
18
21
}
19
22
{% endif %}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ server {
16
16
17
17
{{ advanced_config }}
18
18
19
+ {% if use_default_location %}
19
20
location / {
20
21
{%- if access_list_id > 0 -%}
21
22
# Access List
@@ -35,5 +36,7 @@ server {
35
36
# Proxy!
36
37
include conf.d/include/proxy.conf;
37
38
}
39
+ {% endif %}
40
+
38
41
}
39
42
{% endif %}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ server {
12
12
13
13
{{ advanced_config }}
14
14
15
+ {% if use_default_location %}
15
16
location / {
16
17
{% include "_forced_ssl.conf" %}
17
18
{% include "_hsts.conf" %}
@@ -22,5 +23,7 @@ server {
22
23
return 301 $scheme://{{ forward_domain_name }};
23
24
{% endif %}
24
25
}
26
+ {% endif %}
27
+
25
28
}
26
29
{% endif %}
Original file line number Diff line number Diff line change 152
152
<div role =" tabpanel" class =" tab-pane" id =" advanced" >
153
153
<div class =" row" >
154
154
<div class =" col-md-12" >
155
+ <p >Nginx variables available to you are:</p >
156
+ <ul class =" text-monospace" >
157
+ <li >$server # Host/IP</li >
158
+ <li >$port # Port Number</li >
159
+ <li >$forward_scheme # http or https</li >
160
+ </ul >
155
161
<div class =" form-group mb-0" >
156
162
<label class =" form-label" ><% - i18n (' all-hosts' , ' advanced-config' ) %> </label >
157
163
<textarea name =" advanced_config" rows =" 8" class =" form-control text-monospace" placeholder =" # <%- i18n('all-hosts', 'advanced-warning') %>" ><% - advanced_config %> </textarea >
You can’t perform that action at this time.
0 commit comments