Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-static
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-static
Commits
6fe82621
Commit
6fe82621
authored
May 19, 2015
by
Terence Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom routes
parent
19576666
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
12 deletions
+44
-12
make-config
scripts/config/make-config
+38
-12
nginx.conf.erb
scripts/config/templates/nginx.conf.erb
+6
-0
No files found.
scripts/config/make-config
View file @
6fe82621
...
...
@@ -11,18 +11,44 @@ require 'json'
class
NginxConfig
json
=
{}
json
=
JSON
.
parse
(
File
.
read
(
USER_CONFIG
))
if
File
.
exist?
(
USER_CONFIG
)
json
[
"port"
]
||=
ENV
[
"PORT"
]
||
5000
json
[
"root"
]
||=
"public_html/"
json
[
"proxies"
]
||=
{}
json
[
"clean_urls"
]
||=
false
json
.
each
do
|
key
,
value
|
define_method
(
key
)
{
value
}
def
initialize
(
json_file
)
json
=
{}
json
=
JSON
.
parse
(
File
.
read
(
json_file
))
if
File
.
exist?
(
json_file
)
json
[
"port"
]
||=
ENV
[
"PORT"
]
||
5000
json
[
"root"
]
||=
"public_html/"
json
[
"proxies"
]
||=
{}
json
[
"clean_urls"
]
||=
false
json
[
"routes"
]
||=
{}
json
[
"routes"
]
=
Hash
[
json
[
"routes"
].
map
{
|
route
,
target
|
[
to_regex
(
route
),
target
]
}]
json
.
each
do
|
key
,
value
|
self
.
class
.
send
(
:define_method
,
key
)
{
value
}
end
end
def
context
binding
end
private
def
to_regex
(
path
)
segments
=
[]
while
!
path
.
empty?
if
path
[
0
...
2
]
==
'**'
segments
<<
'.*'
path
=
path
[
2
..-
1
]
elsif
path
[
0
...
1
]
==
'*'
segments
<<
'[^/]*'
path
=
path
[
1
..-
1
]
else
next_star
=
path
.
index
(
"*"
)
||
path
.
length
segments
<<
Regexp
.
escape
(
path
[
0
...
next_star
])
path
=
path
[
next_star
..-
1
]
end
end
segments
.
join
end
end
erb
=
ERB
.
new
(
File
.
read
(
TEMPLATE
))
klass
=
erb
.
def_class
(
NginxConfig
,
'render()'
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
NGINX_CONFIG
))
File
.
write
(
NGINX_CONFIG
,
klass
.
new
.
render
)
erb
=
ERB
.
new
(
File
.
read
(
TEMPLATE
)).
result
(
NginxConfig
.
new
(
USER_CONFIG
).
context
)
File
.
write
(
NGINX_CONFIG
,
erb
)
scripts/config/templates/nginx.conf.erb
View file @
6fe82621
...
...
@@ -42,6 +42,12 @@ http {
}
<%
end
%>
<%
routes
.
each
do
|
route
,
path
|
%>
location ~ ^
<%=
route
%>
$ {
alias
<%=
root
%>
/
<%=
path
%>
;
}
<%
end
%>
<%
proxies
.
each
do
|
location
,
hash
|
%>
location
<%=
location
%>
{
proxy_pass
<%=
hash
[
'origin'
]
%>
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment