Skip to content

Commit d36665e

Browse files
committed
format codebase with prettier
1 parent 023293f commit d36665e

23 files changed

Lines changed: 2199 additions & 1886 deletions

.github/dependabot.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 2
22
updates:
3-
- package-ecosystem: github-actions
4-
directory: "/"
5-
schedule:
6-
interval: "daily"
7-
target-branch: "master"
8-
- package-ecosystem: npm
9-
directory: "/"
10-
schedule:
11-
interval: "daily"
12-
target-branch: "master"
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
target-branch: "master"
8+
- package-ecosystem: npm
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
target-branch: "master"

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
node-version: [20.x, 22.x, 23.x]
1818

1919
steps:
20-
- uses: actions/checkout@v5
21-
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v6
23-
with:
24-
node-version: ${{ matrix.node-version }}
25-
cache: 'yarn'
26-
- run: yarn install --frozen-lockfile
27-
- run: yarn test
20+
- uses: actions/checkout@v5
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v6
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: "yarn"
26+
- run: yarn install --frozen-lockfile
27+
- run: yarn test

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3-
- 10
3+
- 10
44
script:
5-
- npm test
5+
- npm test

lib/app.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
11
/* jshint node: true */
22
"use strict";
33

4-
var exists = require('./exists');
5-
var options = require('./options');
6-
var makeserver = require('./makeserver');
4+
var exists = require("./exists");
5+
var options = require("./options");
6+
var makeserver = require("./makeserver");
77

88
options.init(false);
99

10-
console.log('Serving directory "' + options.wwwroot + '" on port ' + options.port + ' to ' + (options.listenHost ? options.listenHost: 'the world') + '.');
10+
console.log(
11+
'Serving directory "' +
12+
options.wwwroot +
13+
'" on port ' +
14+
options.port +
15+
" to " +
16+
(options.listenHost ? options.listenHost : "the world") +
17+
"."
18+
);
1119

1220
function warn(message) {
13-
console.warn('Warning: ' + message);
21+
console.warn("Warning: " + message);
1422
}
1523

1624
if (!exists(options.wwwroot)) {
17-
warn('"' + options.wwwroot + '" does not exist.');
18-
} else if (!exists(options.wwwroot + '/index.html')) {
19-
warn('"' + options.wwwroot + '" is not a TerriaJS wwwroot directory.');
20-
} else if (!exists(options.wwwroot + '/build')) {
21-
warn('"' + options.wwwroot + '" has not been built. You should do this:\n\n' +
22-
'> cd ' + options.wwwroot + '/..\n' +
23-
'> gulp\n');
25+
warn('"' + options.wwwroot + '" does not exist.');
26+
} else if (!exists(options.wwwroot + "/index.html")) {
27+
warn('"' + options.wwwroot + '" is not a TerriaJS wwwroot directory.');
28+
} else if (!exists(options.wwwroot + "/build")) {
29+
warn(
30+
'"' +
31+
options.wwwroot +
32+
'" has not been built. You should do this:\n\n' +
33+
"> cd " +
34+
options.wwwroot +
35+
"/..\n" +
36+
"> gulp\n"
37+
);
2438
}
2539

26-
if (typeof options.settings.allowProxyFor === 'undefined') {
27-
warn('The configuration does not contain a "allowProxyFor" list. The server will proxy _any_ request.');
40+
if (typeof options.settings.allowProxyFor === "undefined") {
41+
warn(
42+
'The configuration does not contain a "allowProxyFor" list. The server will proxy _any_ request.'
43+
);
2844
}
2945

3046
const server = makeserver(options).listen(options.port, options.listenHost);
3147

32-
server.on('error', (err) => {
33-
if (err.code === 'EADDRINUSE') {
34-
console.error(`Port ${options.port} is already in use`);
35-
process.exit(1);
36-
} else {
37-
console.error(err);
38-
}
48+
server.on("error", (err) => {
49+
if (err.code === "EADDRINUSE") {
50+
console.error(`Port ${options.port} is already in use`);
51+
process.exit(1);
52+
} else {
53+
console.error(err);
54+
}
3955
});

lib/controllers/esri-token-auth.js

Lines changed: 110 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,132 @@
11
/* jshint node: true, esnext: true */
22
"use strict";
3-
var router = require('express').Router();
4-
var request = require('request');
5-
var bodyParser = require('body-parser');
6-
var url = require('url');
7-
8-
module.exports = function(options) {
9-
if (!options || !options.servers) {
10-
return;
3+
var router = require("express").Router();
4+
var request = require("request");
5+
var bodyParser = require("body-parser");
6+
var url = require("url");
7+
8+
module.exports = function (options) {
9+
if (!options || !options.servers) {
10+
return;
11+
}
12+
13+
// The maximum size of the JSON data.
14+
let postSizeLimit = options.postSizeLimit || "1024";
15+
16+
let tokenServers = parseUrls(options.servers);
17+
tokenServers = validateServerConfig(tokenServers);
18+
19+
router.use(
20+
bodyParser.json({ limit: postSizeLimit, type: "application/json" })
21+
);
22+
router.post("/", function (req, res, next) {
23+
let parameters = req.body;
24+
25+
if (!parameters.url) {
26+
return res.status(400).send("No URL specified.");
1127
}
1228

13-
// The maximum size of the JSON data.
14-
let postSizeLimit = options.postSizeLimit || '1024';
15-
16-
let tokenServers = parseUrls(options.servers);
17-
tokenServers = validateServerConfig(tokenServers);
18-
19-
router.use(bodyParser.json({limit:postSizeLimit, type:'application/json'}));
20-
router.post('/', function(req, res, next) {
21-
let parameters = req.body;
29+
let targetUrl = parseUrl(parameters.url);
30+
if (!targetUrl || targetUrl.length === 0 || typeof targetUrl !== "string") {
31+
return res.status(400).send("Invalid URL specified.");
32+
}
2233

23-
if (!parameters.url) {
24-
return res.status(400).send('No URL specified.');
25-
}
34+
let tokenServer = tokenServers[targetUrl];
35+
if (!tokenServer) {
36+
return res.status(400).send("Unsupported URL specified.");
37+
}
2638

27-
let targetUrl = parseUrl(parameters.url);
28-
if (!targetUrl || (targetUrl.length === 0) || (typeof targetUrl !== 'string')) {
29-
return res.status(400).send('Invalid URL specified.');
39+
request(
40+
{
41+
url: tokenServer.tokenUrl,
42+
method: "POST",
43+
headers: {
44+
"User-Agent": "TerriaJSESRITokenAuth"
45+
},
46+
form: {
47+
username: tokenServer.username,
48+
password: tokenServer.password,
49+
f: "JSON"
3050
}
31-
32-
let tokenServer = tokenServers[targetUrl];
33-
if (!tokenServer) {
34-
return res.status(400).send('Unsupported URL specified.');
51+
},
52+
function (error, response, body) {
53+
try {
54+
res.set("Content-Type", "application/json");
55+
56+
if (response.statusCode !== 200) {
57+
return res.status(502).send("Token server failed.");
58+
} else {
59+
let value = JSON.parse(response.body);
60+
return res.status(200).send(JSON.stringify(value));
61+
}
62+
} catch (error) {
63+
return res.status(500).send("Error processing server response.");
3564
}
65+
}
66+
);
67+
});
3668

37-
request({
38-
url: tokenServer.tokenUrl,
39-
method: 'POST',
40-
headers: {
41-
'User-Agent': 'TerriaJSESRITokenAuth',
42-
},
43-
form:{
44-
username: tokenServer.username,
45-
password: tokenServer.password,
46-
f: 'JSON'
47-
}
48-
}, function(error, response, body) {
49-
try {
50-
res.set('Content-Type', 'application/json');
51-
52-
if (response.statusCode !== 200) {
53-
return res.status(502).send('Token server failed.');
54-
} else {
55-
let value = JSON.parse(response.body);
56-
return res.status(200).send(JSON.stringify(value));
57-
}
58-
}
59-
catch (error) {
60-
return res.status(500).send('Error processing server response.');
61-
}
62-
});
63-
});
64-
65-
return router;
69+
return router;
6670
};
6771

6872
function parseUrls(servers) {
69-
let result = {};
70-
71-
Object.keys(servers).forEach(server => {
72-
let parsedUrl = parseUrl(server)
73-
if (parsedUrl) {
74-
result[parsedUrl] = servers[server];
75-
}
76-
else {
77-
console.error('Invalid configuration. The URL: \'' + server + '\' is not valid.');
78-
}
79-
});
73+
let result = {};
74+
75+
Object.keys(servers).forEach((server) => {
76+
let parsedUrl = parseUrl(server);
77+
if (parsedUrl) {
78+
result[parsedUrl] = servers[server];
79+
} else {
80+
console.error(
81+
"Invalid configuration. The URL: '" + server + "' is not valid."
82+
);
83+
}
84+
});
8085

81-
return result;
86+
return result;
8287
}
8388

8489
function parseUrl(urlString) {
85-
try {
86-
return url.format(url.parse(urlString));
87-
}
88-
catch (error) {
89-
return '';
90-
}
90+
try {
91+
return url.format(url.parse(urlString));
92+
} catch (error) {
93+
return "";
94+
}
9195
}
9296

93-
function validateServerConfig(servers)
94-
{
95-
let result = {};
96-
97-
Object.keys(servers).forEach(url => {
98-
let server = servers[url];
99-
if (server.username && server.password && server.tokenUrl) {
100-
result[url] = server;
101-
102-
// Note: We should really only validate URLs that are HTTPS to save us from ourselves, but the current
103-
// servers we need to support don't support HTTPS :( so the best that we can do is warn against it.
104-
if (!isHttps(server.tokenUrl)) {
105-
console.error('All communications should be TLS but the URL \'' + server.tokenUrl + '\' does not use https.');
106-
}
107-
} else {
108-
console.error('Bad Configuration. \'' + url + '\' does not supply all of the required properties.');
109-
}
110-
});
97+
function validateServerConfig(servers) {
98+
let result = {};
99+
100+
Object.keys(servers).forEach((url) => {
101+
let server = servers[url];
102+
if (server.username && server.password && server.tokenUrl) {
103+
result[url] = server;
104+
105+
// Note: We should really only validate URLs that are HTTPS to save us from ourselves, but the current
106+
// servers we need to support don't support HTTPS :( so the best that we can do is warn against it.
107+
if (!isHttps(server.tokenUrl)) {
108+
console.error(
109+
"All communications should be TLS but the URL '" +
110+
server.tokenUrl +
111+
"' does not use https."
112+
);
113+
}
114+
} else {
115+
console.error(
116+
"Bad Configuration. '" +
117+
url +
118+
"' does not supply all of the required properties."
119+
);
120+
}
121+
});
111122

112-
return result;
123+
return result;
113124
}
114125

115-
function isHttps(urlString){
116-
try {
117-
return (url.parse(urlString).protocol === 'https:')
118-
}
119-
catch (error)
120-
{
121-
return false;
122-
}
126+
function isHttps(urlString) {
127+
try {
128+
return url.parse(urlString).protocol === "https:";
129+
} catch (error) {
130+
return false;
131+
}
123132
}

0 commit comments

Comments
 (0)