Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Aug 20, 2018
1 parent a9afc1a commit a1b620d
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 93 deletions.
60 changes: 30 additions & 30 deletions nsqadmin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type httpServer struct {
router http.Handler
client *http_api.Client
ci *clusterinfo.ClusterInfo
basepath string
basePath string
}

func NewHTTPServer(ctx *Context) *httpServer {
Expand All @@ -71,44 +71,44 @@ func NewHTTPServer(ctx *Context) *httpServer {
router: router,
client: client,
ci: clusterinfo.New(ctx.nsqadmin.logf, client),
basepath: ctx.nsqadmin.getOpts().BasePath,
basePath: ctx.nsqadmin.getOpts().BasePath,
}

router.Handle("GET", s.basepath+"/ping", http_api.Decorate(s.pingHandler, log, http_api.PlainText))
router.Handle("GET", s.basePath+"ping", http_api.Decorate(s.pingHandler, log, http_api.PlainText))

router.Handle("GET", s.basepath+"/", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/topics", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/topics/:topic", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/topics/:topic/:channel", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/nodes", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/nodes/:node", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/counter", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basepath+"/lookup", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"topics", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"topics/:topic", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"topics/:topic/:channel", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"nodes", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"nodes/:node", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"counter", http_api.Decorate(s.indexHandler, log))
router.Handle("GET", s.basePath+"lookup", http_api.Decorate(s.indexHandler, log))

router.Handle("GET", s.basepath+"/static/:asset", http_api.Decorate(s.staticAssetHandler, log, http_api.PlainText))
router.Handle("GET", s.basepath+"/fonts/:asset", http_api.Decorate(s.staticAssetHandler, log, http_api.PlainText))
router.Handle("GET", s.basePath+"static/:asset", http_api.Decorate(s.staticAssetHandler, log, http_api.PlainText))
router.Handle("GET", s.basePath+"fonts/:asset", http_api.Decorate(s.staticAssetHandler, log, http_api.PlainText))
if s.ctx.nsqadmin.getOpts().ProxyGraphite {
proxy := NewSingleHostReverseProxy(ctx.nsqadmin.graphiteURL, ctx.nsqadmin.getOpts().HTTPClientConnectTimeout,
ctx.nsqadmin.getOpts().HTTPClientRequestTimeout)
router.Handler("GET", s.basepath+"/render", proxy)
router.Handler("GET", s.basePath+"render", proxy)
}

// v1 endpoints
router.Handle("GET", s.basepath+"/api/topics", http_api.Decorate(s.topicsHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/topics/:topic", http_api.Decorate(s.topicHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/topics/:topic/:channel", http_api.Decorate(s.channelHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/nodes", http_api.Decorate(s.nodesHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/nodes/:node", http_api.Decorate(s.nodeHandler, log, http_api.V1))
router.Handle("POST", s.basepath+"/api/topics", http_api.Decorate(s.createTopicChannelHandler, log, http_api.V1))
router.Handle("POST", s.basepath+"/api/topics/:topic", http_api.Decorate(s.topicActionHandler, log, http_api.V1))
router.Handle("POST", s.basepath+"/api/topics/:topic/:channel", http_api.Decorate(s.channelActionHandler, log, http_api.V1))
router.Handle("DELETE", s.basepath+"/api/nodes/:node", http_api.Decorate(s.tombstoneNodeForTopicHandler, log, http_api.V1))
router.Handle("DELETE", s.basepath+"/api/topics/:topic", http_api.Decorate(s.deleteTopicHandler, log, http_api.V1))
router.Handle("DELETE", s.basepath+"/api/topics/:topic/:channel", http_api.Decorate(s.deleteChannelHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/counter", http_api.Decorate(s.counterHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/api/graphite", http_api.Decorate(s.graphiteHandler, log, http_api.V1))
router.Handle("GET", s.basepath+"/config/:opt", http_api.Decorate(s.doConfig, log, http_api.V1))
router.Handle("PUT", s.basepath+"/config/:opt", http_api.Decorate(s.doConfig, log, http_api.V1))
router.Handle("GET", s.basePath+"api/topics", http_api.Decorate(s.topicsHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/topics/:topic", http_api.Decorate(s.topicHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/topics/:topic/:channel", http_api.Decorate(s.channelHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/nodes", http_api.Decorate(s.nodesHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/nodes/:node", http_api.Decorate(s.nodeHandler, log, http_api.V1))
router.Handle("POST", s.basePath+"api/topics", http_api.Decorate(s.createTopicChannelHandler, log, http_api.V1))
router.Handle("POST", s.basePath+"api/topics/:topic", http_api.Decorate(s.topicActionHandler, log, http_api.V1))
router.Handle("POST", s.basePath+"api/topics/:topic/:channel", http_api.Decorate(s.channelActionHandler, log, http_api.V1))
router.Handle("DELETE", s.basePath+"api/nodes/:node", http_api.Decorate(s.tombstoneNodeForTopicHandler, log, http_api.V1))
router.Handle("DELETE", s.basePath+"api/topics/:topic", http_api.Decorate(s.deleteTopicHandler, log, http_api.V1))
router.Handle("DELETE", s.basePath+"api/topics/:topic/:channel", http_api.Decorate(s.deleteChannelHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/counter", http_api.Decorate(s.counterHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"api/graphite", http_api.Decorate(s.graphiteHandler, log, http_api.V1))
router.Handle("GET", s.basePath+"config/:opt", http_api.Decorate(s.doConfig, log, http_api.V1))
router.Handle("PUT", s.basePath+"config/:opt", http_api.Decorate(s.doConfig, log, http_api.V1))

return s
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request, ps h
StatsdPrefix: s.ctx.nsqadmin.getOpts().StatsdPrefix,
NSQLookupd: s.ctx.nsqadmin.getOpts().NSQLookupdHTTPAddresses,
IsAdmin: s.isAuthorizedAdminRequest(req),
BasePath: s.basepath,
BasePath: s.basePath,
})

return nil, nil
Expand Down
23 changes: 12 additions & 11 deletions nsqadmin/nsqadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,19 @@ func New(opts *Options) *NSQAdmin {
return n
}

func normalizeBasePath(basepath string) string {
if len(basepath) > 0 {
// add leading slash
if basepath[0] != '/' {
basepath = "/" + basepath
}
// remove trailing slash
if basepath[len(basepath)-1] == '/' {
basepath = basepath[:len(basepath)-1]
}
func normalizeBasePath(p string) string {
if len(p) == 0 {
return "/"
}
// add leading slash
if p[0] != '/' {
p = "/" + p
}
// add trailing slash
if p[len(p)-1] != '/' {
p = p + "/"
}
return basepath
return p
}

func (n *NSQAdmin) getOpts() *Options {
Expand Down
10 changes: 5 additions & 5 deletions nsqadmin/static/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<title>nsqadmin</title>
<link rel="icon" type="image/png" href="{{.BasePath}}/static/favicon.png">
<link rel="stylesheet" href="{{.BasePath}}/static/bootstrap.min.css">
<link rel="stylesheet" href="{{.BasePath}}/static/base.css">
<link rel="icon" type="image/png" href="{{.BasePath}}static/favicon.png">
<link rel="stylesheet" href="{{.BasePath}}static/bootstrap.min.css">
<link rel="stylesheet" href="{{.BasePath}}static/base.css">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
Expand All @@ -26,7 +26,7 @@
var IS_ADMIN ={{.IsAdmin}};
var BASE_PATH = '{{.BasePath}}';
</script>
<script src="{{.BasePath}}/static/vendor.js"></script>
<script src="{{.BasePath}}/static/main.js"></script>
<script src="{{.BasePath}}static/vendor.js"></script>
<script src="{{.BasePath}}static/main.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion nsqadmin/static/js/app_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var AppState = Backbone.Model.extend({
},

url: function(url) {
return this.get('BASE_PATH') + '/api' + url;
return this.get('BASE_PATH') + 'api' + url;
}
});

Expand Down
37 changes: 17 additions & 20 deletions nsqadmin/static/js/router.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
var Backbone = require('backbone');

var AppState = require('./app_state');
var Pubsub = require('./lib/pubsub');


var Router = Backbone.Router.extend({
routes: {
'*base_path/': 'topics',
'*base_path/topics/(:topic)(/:channel)': 'topic',
'*base_path/lookup': 'lookup',
'*base_path/nodes(/:node)': 'nodes',
'*base_path/counter': 'counter'
},

defaultRoute: 'topics',

initialize: function() {
this.currentRoute = this.defaultRoute;
this.listenTo(this, 'route', function(route, params) {
this.currentRoute = route || this.defaultRoute;
// console.log('Route: %o; params: %o', route, params);
});
var bp = AppState.get('BASE_PATH');
bp = bp == '/' ? '' : bp;
this.route(bp, 'topics');
this.route(bp+'topics/(:topic)(/:channel)', 'topic');
this.route(bp+'lookup', 'lookup');
this.route(bp+'nodes(/:node)', 'nodes');
this.route(bp+'counter', 'counter');
// this.listenTo(this, 'route', function(route, params) {
// console.log('Route: %o; params: %o', route, params);
// });
},

start: function() {
Backbone.history.start({
'root': AppState.get('BASE_PATH'),
'pushState': true
});
},

topics: function(base_path) {
topics: function() {
Pubsub.trigger('topics:show');
},

topic: function(base_path, topic, channel) {
topic: function(topic, channel) {
if (channel !== null) {
Pubsub.trigger('channel:show', topic, channel);
return;
}
Pubsub.trigger('topic:show', topic);
},

lookup: function(base_path) {
lookup: function() {
Pubsub.trigger('lookup:show');
},

nodes: function(base_path, node) {
nodes: function(node) {
if (node !== null) {
Pubsub.trigger('node:show', node);
return;
}
Pubsub.trigger('nodes:show');
},

counter: function(base_path) {
counter: function() {
Pubsub.trigger('counter:show');
}
});
Expand Down
12 changes: 6 additions & 6 deletions nsqadmin/static/js/views/channel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{> error}}

<ol class="breadcrumb">
<li><a class="link" href="{{base_path}}/">Streams</a>
<li><a class="link" href="{{base_path}}/topics/{{urlencode topic}}">{{topic}}</a>
<li><a class="link" href="{{base_path}}">Streams</a>
<li><a class="link" href="{{base_path}}topics/{{urlencode topic}}">{{topic}}</a>
<li class="active">{{name}}</li>
</ol>

Expand All @@ -21,7 +21,7 @@
<div class="col-md-6">
<div class="alert alert-warning">
<h4>Notice</h4> No producers exist for this topic/channel.
<p>See <a class="link" href="{{base_path}}/lookup">Lookup</a> for more information.
<p>See <a class="link" href="{{base_path}}lookup">Lookup</a> for more information.
</div>
</div>
</div>
Expand Down Expand Up @@ -75,9 +75,9 @@
<tr>
<td>
{{#if show_broadcast_address}}
{{hostname_port}} (<a class="link" href="{{../base_path}}/nodes/{{node}}">{{node}}</a>)
{{hostname_port}} (<a class="link" href="{{../base_path}}nodes/{{node}}">{{node}}</a>)
{{else}}
<a class="link" href="{{../base_path}}/nodes/{{node}}">{{hostname_port}}</a>
<a class="link" href="{{../base_path}}nodes/{{node}}">{{hostname_port}}</a>
{{/if}}
{{#if paused}} <span class="label label-primary">paused</span>{{/if}}
</td>
Expand Down Expand Up @@ -210,7 +210,7 @@
</span>
{{/if}}
</td>
<td><a class="link" href="{{../base_path}}/nodes/{{node}}">{{node}}</a></td>
<td><a class="link" href="{{../base_path}}nodes/{{node}}">{{node}}</a></td>
<td>{{commafy in_flight_count}}</td>
<td>{{commafy ready_count}}</td>
<td>{{commafy finish_count}}</td>
Expand Down
2 changes: 1 addition & 1 deletion nsqadmin/static/js/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var ChannelView = BaseView.extend({
var topic_name = this.model.get('topic');
$.ajax(this.model.url(), {'method': 'DELETE'})
.done(function() {
window.location = AppState.get('BASE_PATH') + '/topics/' + encodeURIComponent(topic_name);
window.location = AppState.get('BASE_PATH') + 'topics/' + encodeURIComponent(topic_name);
})
.fail(this.handleAJAXError.bind(this));
} else {
Expand Down
10 changes: 5 additions & 5 deletions nsqadmin/static/js/views/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{base_path}}/"><img src="{{base_path}}/static/nsq_blue.png" width="30" height="30">NSQ</a>
<a class="navbar-brand" href="{{base_path}}"><img src="{{base_path}}static/nsq_blue.png" width="30" height="30">NSQ</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
<li><a class="link" href="{{base_path}}/">Streams</a></li>
<li><a class="link" href="{{base_path}}/nodes">Nodes</a></li>
<li><a class="link" href="{{base_path}}/counter">Counter</a></li>
<li><a class="link" href="{{base_path}}/lookup">Lookup</a></li>
<li><a class="link" href="{{base_path}}">Streams</a></li>
<li><a class="link" href="{{base_path}}nodes">Nodes</a></li>
<li><a class="link" href="{{base_path}}counter">Counter</a></li>
<li><a class="link" href="{{base_path}}lookup">Lookup</a></li>
{{#if graph_enabled}}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-picture white"></span> {{graph_interval}} <span class="caret"></span></a>
Expand Down
4 changes: 2 additions & 2 deletions nsqadmin/static/js/views/lookup.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<ul>
{{#each topics}}
<li>
<button class="btn-link red delete-topic-link" data-topic="{{name}}" style="padding: 0 6px; border: 0;">✘</button> <a class="link" href="{{../base_path}}/topics/{{name}}">{{name}}</a>
<button class="btn-link red delete-topic-link" data-topic="{{name}}" style="padding: 0 6px; border: 0;">✘</button> <a class="link" href="{{../base_path}}topics/{{name}}">{{name}}</a>
<ul>
{{#each channels}}
<li>
<button class="btn-link red delete-channel-link" data-topic="{{../name}}" data-channel="{{this}}" style="padding: 0 6px; border: 0;">✘</button> <a class="link" href="{{../../base_path}}/topics/{{../name}}/{{this}}">{{this}}</a>
<button class="btn-link red delete-channel-link" data-topic="{{../name}}" data-channel="{{this}}" style="padding: 0 6px; border: 0;">✘</button> <a class="link" href="{{../../base_path}}topics/{{../name}}/{{this}}">{{this}}</a>
</li>
{{/each}}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion nsqadmin/static/js/views/node.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{> error}}

<ol class="breadcrumb">
<li><a class="link" href="{{base_path}}/nodes">Nodes</a>
<li><a class="link" href="{{base_path}}nodes">Nodes</a>
<li class="active">{{name}}</li>
</ol>

Expand Down
4 changes: 2 additions & 2 deletions nsqadmin/static/js/views/nodes.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{#each collection}}
<tr {{#if out_of_date}}class="warning"{{/if}}>
<td>{{hostname}}</td>
<td><a class="link" href="{{../base_path}}/nodes/{{broadcast_address}}:{{http_port}}">{{broadcast_address}}</a></td>
<td><a class="link" href="{{../base_path}}nodes/{{broadcast_address}}:{{http_port}}">{{broadcast_address}}</a></td>
<td>{{tcp_port}}</td>
<td>{{http_port}}</td>
<td>{{version}}</td>
Expand All @@ -40,7 +40,7 @@
{{#if topics.length}}
<span class="badge">{{topics.length}}</span>
{{#each topics}}
<a href="{{../../base_path}}/topics/{{topic}}" class="link label {{#if tombstoned}}label-warning{{else}}label-primary{{/if}}" {{#if tombstoned}}title="this topic is currently tombstoned on this node"{{/if}}>{{topic}}</a>
<a href="{{../../base_path}}topics/{{topic}}" class="link label {{#if tombstoned}}label-warning{{else}}label-primary{{/if}}" {{#if tombstoned}}title="this topic is currently tombstoned on this node"{{/if}}>{{topic}}</a>
{{/each}}
{{/if}}
</td>
Expand Down
10 changes: 5 additions & 5 deletions nsqadmin/static/js/views/topic.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{> error}}

<ol class="breadcrumb">
<li><a class="link" href="{{base_path}}/">Streams</a>
<li><a class="link" href="{{base_path}}">Streams</a>
<li class="active">{{name}}</li>
</ol>

Expand All @@ -20,7 +20,7 @@
<h4>Topic Message Queue</h4>
<div class="alert alert-warning">
<h4>Notice</h4> No producers exist for this topic.
<p>See <a href="{{base_path}}/lookup">Lookup</a> for more information.
<p>See <a href="{{base_path}}lookup">Lookup</a> for more information.
</div>
</div>
</div>
Expand Down Expand Up @@ -69,9 +69,9 @@
<td>
<button class="btn-link red tombstone-link" data-node="{{node}}" data-topic="{{../name}}" style="padding: 0 6px; border: 0;">✘</button>
{{#if show_broadcast_address}}
{{hostname_port}} (<a class="link" href="{{../base_path}}/nodes/{{node}}">{{node}}</a>)
{{hostname_port}} (<a class="link" href="{{../base_path}}nodes/{{node}}">{{node}}</a>)
{{else}}
<a class="link" href="{{../base_path}}/nodes/{{node}}">{{hostname_port}}</a>
<a class="link" href="{{../base_path}}nodes/{{node}}">{{hostname_port}}</a>
{{/if}}
{{#if paused}} <span class="label label-primary">paused</span>{{/if}}
</td>
Expand Down Expand Up @@ -178,7 +178,7 @@
{{#each channels}}
<tr>
<th>
<a class="link" href="{{../base_path}}/topics/{{urlencode topic_name}}/{{urlencode channel_name}}">{{channel_name}}</a>
<a class="link" href="{{../base_path}}topics/{{urlencode topic_name}}/{{urlencode channel_name}}">{{channel_name}}</a>
{{#if paused}}<span class="label label-primary">paused</span>{{/if}}
</th>
<td>{{commafy depth}}</td>
Expand Down
2 changes: 1 addition & 1 deletion nsqadmin/static/js/views/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var TopicView = BaseView.extend({
}
if (action === 'delete') {
$.ajax(this.model.url(), {'method': 'DELETE'})
.done(function() { window.location = AppState.get('BASE_PATH') + '/'; });
.done(function() { window.location = AppState.get('BASE_PATH'); });
} else {
$.post(this.model.url(), JSON.stringify({'action': action}))
.done(function() { window.location.reload(true); })
Expand Down
Loading

0 comments on commit a1b620d

Please sign in to comment.