Skip to content

Commit 287948c

Browse files
authored
Proxy for making autocomplete calls (#53)
* Proxy for making autocomplete calls * missing semi-colon
1 parent 4f1b3ad commit 287948c

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

app.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var express = require('express'),
1313
isloggedin = require('./lib/isloggedin.js'),
1414
sssenv = require('./lib/sssenv.js'),
1515
inference = require('./lib/inference.js'),
16-
autocomplete = require('./lib/autocomplete.js');
16+
autocomplete = require('./lib/autocomplete.js'),
17+
request = require('request');
1718

1819
// socket.io and express config
1920
var http = require('http').Server(app);
@@ -447,6 +448,32 @@ app.post('/service/disable/metrics', isloggedin.auth, function(req, res) {
447448

448449
});
449450

451+
// Get autocomplete from SAS
452+
app.get('/do/autocomplete/:key', isloggedin.auth, function(req, res) {
453+
454+
if (app.locals.autocomplete && app.locals.autocomplete.enabled) {
455+
456+
var url = `${app.locals.autocomplete.host}/api/sss_${req.params.key}?term=${req.query.term}`;
457+
458+
request(url, function(e, r, b) {
459+
460+
var terms = [];
461+
try {
462+
terms = JSON.parse(b);
463+
} catch (e) {}
464+
465+
return res.send(terms);
466+
467+
});
468+
469+
}
470+
471+
else {
472+
return res.status(404).send([]);
473+
}
474+
475+
});
476+
450477
// start server on the specified port and binding host
451478
http.listen(appEnv.port, "0.0.0.0", function() {
452479

views/templates/add.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,10 @@ <h1 class="type_heading"><mark class="type_mark">Add row</mark></h1>
6161
var autocomplete = $(e).attr("data-autocomplete");
6262
if (autocomplete) {
6363

64-
var host = _config.autocomplete.host;
65-
if (_config.autocomplete.username && _config.autocomplete.password) {
66-
var bits = _config.autocomplete.host.split("//");
67-
host = bits[0] + "//" + _config.autocomplete.username + ":" + _config.autocomplete.password + "@" + bits[1];
68-
}
69-
7064
$(e).autocomplete({
71-
source: host + "/api/sss_" + encodeURIComponent(autocomplete)
65+
source: "/do/autocomplete/" + encodeURIComponent(autocomplete)
7266
});
67+
7368
}
7469

7570
});

views/templates/edit.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,8 @@ <h1 class="type_heading"><mark class="type_mark">Edit Row</mark></h1>
6868
var autocomplete = $(e).attr("data-autocomplete");
6969
if (autocomplete) {
7070

71-
var host = _config.autocomplete.host;
72-
if (_config.autocomplete.username && _config.autocomplete.password) {
73-
var bits = _config.autocomplete.host.split("//");
74-
host = bits[0] + "//" + _config.autocomplete.username + ":" + _config.autocomplete.password + "@" + bits[1];
75-
}
76-
7771
$(e).autocomplete({
78-
source: host + "/api/sss_" + encodeURIComponent(autocomplete)
72+
source: "/do/autocomplete/" + encodeURIComponent(autocomplete)
7973
});
8074
}
8175

0 commit comments

Comments
 (0)