Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
ff64d30c
Commit
ff64d30c
authored
Jan 31, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add webpack dev-server support
parent
815be1cc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
0 deletions
+87
-0
internal/config/config.go
internal/config/config.go
+1
-0
internal/upstream/routes.go
internal/upstream/routes.go
+13
-0
internal/webpack/devserver.go
internal/webpack/devserver.go
+38
-0
internal/webpack/devserver_test.go
internal/webpack/devserver_test.go
+33
-0
main.go
main.go
+2
-0
No files found.
internal/config/config.go
View file @
ff64d30c
...
...
@@ -10,6 +10,7 @@ type Config struct {
Version
string
DocumentRoot
string
DevelopmentMode
bool
WebpackAddr
string
Socket
string
ProxyHeadersTimeout
time
.
Duration
APILimit
uint
...
...
internal/upstream/routes.go
View file @
ff64d30c
...
...
@@ -19,6 +19,7 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/staticpages"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/terminal"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/upload"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/webpack"
)
type
matcherFunc
func
(
*
http
.
Request
)
bool
...
...
@@ -139,6 +140,18 @@ func (u *Upstream) configureRoutes() {
route
(
""
,
apiPattern
,
proxy
),
route
(
""
,
ciAPIPattern
,
proxy
),
// In development mode, proxy /assets/webpack requests to webpack
// dev-server, otherwise serve static files from disk.
route
(
""
,
`^/assets/webpack/`
,
webpack
.
DevServer
(
u
.
DevelopmentMode
,
u
.
WebpackAddr
,
static
.
ServeExisting
(
u
.
URLPrefix
,
staticpages
.
CacheExpireMax
,
nil
,
)),
),
// Serve assets
route
(
""
,
`^/assets/`
,
...
...
internal/webpack/devserver.go
0 → 100644
View file @
ff64d30c
package
webpack
import
(
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
func
DevServer
(
enabled
bool
,
address
string
,
fallbackHandler
http
.
Handler
)
http
.
Handler
{
if
!
enabled
{
return
fallbackHandler
}
u
,
err
:=
buildURL
(
address
)
if
err
!=
nil
{
panic
(
err
)
}
return
httputil
.
NewSingleHostReverseProxy
(
u
)
}
func
buildURL
(
address
string
)
(
*
url
.
URL
,
error
)
{
u
:=
helper
.
URLMustParse
(
address
)
if
u
==
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to parse URL in %q"
,
address
)
}
// Hope to support unix:// in the future
if
u
.
Scheme
!=
"tcp"
{
return
nil
,
fmt
.
Errorf
(
"invalid scheme: %v"
,
u
)
}
u
.
Scheme
=
"http"
return
u
,
nil
}
internal/webpack/devserver_test.go
0 → 100644
View file @
ff64d30c
package
webpack
import
(
"testing"
)
func
TestBuildURL
(
t
*
testing
.
T
)
{
examples
:=
[]
struct
{
input
string
ok
bool
}{
{
""
,
false
},
{
"localhost:5000"
,
false
},
{
"tcp://localhost:5000"
,
true
},
}
for
_
,
ex
:=
range
examples
{
u
,
err
:=
buildURL
(
ex
.
input
)
if
ex
.
ok
{
if
err
!=
nil
{
t
.
Errorf
(
"example %v: expected no error, got %v"
,
ex
,
err
)
}
expectedScheme
:=
"http"
if
u
.
Scheme
!=
expectedScheme
{
t
.
Errorf
(
"example %v: expected scheme %q, got %q"
,
ex
,
expectedScheme
,
u
.
Scheme
)
}
}
else
{
if
err
==
nil
{
t
.
Errorf
(
"example %v: expected error, got none"
,
ex
)
}
}
}
}
main.go
View file @
ff64d30c
...
...
@@ -51,6 +51,7 @@ var apiQueueLimit = flag.Uint("apiQueueLimit", 0, "Number of API requests allowe
var
apiQueueTimeout
=
flag
.
Duration
(
"apiQueueDuration"
,
queueing
.
DefaultTimeout
,
"Maximum queueing duration of requests"
)
var
logFile
=
flag
.
String
(
"logFile"
,
""
,
"Log file to be used"
)
var
prometheusListenAddr
=
flag
.
String
(
"prometheusListenAddr"
,
""
,
"Prometheus listening address, e.g. ':9100'"
)
var
webpackAddr
=
flag
.
String
(
"webpackAddr"
,
""
,
"(development mode only) Network address of Webpack dev server, e.g. 'tcp://localhost:5000'"
)
func
main
()
{
flag
.
Usage
=
func
()
{
...
...
@@ -115,6 +116,7 @@ func main() {
Version
:
Version
,
DocumentRoot
:
*
documentRoot
,
DevelopmentMode
:
*
developmentMode
,
WebpackAddr
:
*
webpackAddr
,
ProxyHeadersTimeout
:
*
proxyHeadersTimeout
,
APILimit
:
*
apiLimit
,
APIQueueLimit
:
*
apiQueueLimit
,
...
...
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