Skip to content

Commit

Permalink
Fix SSF-122 (#2161)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5f1f8e8)
  • Loading branch information
yassin-kammoun-sonarsource committed Sep 23, 2020
1 parent ef71e7b commit 89eaee7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion eslint-bridge/bin/server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

const server = require("../lib/server");
server.start(process.argv[2]);
server.start(process.argv[2], process.argv[3]);
9 changes: 5 additions & 4 deletions eslint-bridge/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ import { getFilesForTsConfig } from './tsconfig';

const MAX_REQUEST_SIZE = '50mb';

export function start(port = 0): Promise<Server> {
return startServer(port, analyzeJavaScript, analyzeTypeScript);
export function start(port = 0, host = '127.0.0.1'): Promise<Server> {
return startServer(analyzeJavaScript, analyzeTypeScript, port, host);
}

type AnalysisFunction = (input: AnalysisInput) => AnalysisResponse;

// exported for test
export function startServer(
port = 0,
analyzeJS: AnalysisFunction,
analyzeTS: AnalysisFunction,
port = 0,
host = '127.0.0.1',
): Promise<Server> {
return new Promise(resolve => {
console.log('DEBUG starting eslint-bridge server at port', port);
Expand Down Expand Up @@ -82,7 +83,7 @@ export function startServer(
});
});

server = app.listen(port, () => {
server = app.listen(port, host, () => {
console.log(
'DEBUG eslint-bridge server is running at port',
(server.address() as AddressInfo).port,
Expand Down
2 changes: 1 addition & 1 deletion eslint-bridge/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('should send error when failing', () => {
let close;

beforeEach(async () => {
server = await startServer(0, failAnalysis, failAnalysis);
server = await startServer(failAnalysis, failAnalysis, 0, '127.0.0.1');
close = promisify(server.close.bind(server));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.file.Files;
import java.net.InetAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
Expand All @@ -37,7 +38,6 @@
import okhttp3.RequestBody;
import okhttp3.Response;
import org.sonar.api.SonarProduct;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
Expand Down Expand Up @@ -130,7 +130,7 @@ private void initNodeCommand(SensorContext context, File scriptFile) throws IOEx
.minNodeVersion(8)
.configuration(context.config())
.script(scriptFile.getAbsolutePath())
.scriptArgs(String.valueOf(port));
.scriptArgs(String.valueOf(port), InetAddress.getLoopbackAddress().getHostAddress());

context.config()
.getInt(MAX_OLD_SPACE_SIZE_PROPERTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const http = require('http')
const port = process.argv[2]
const host = process.argv[3]

const requestHandler = (request, response) => {
if (request.url == '/status') {
Expand All @@ -18,10 +19,10 @@ const requestHandler = (request, response) => {

const server = http.createServer(requestHandler)

server.listen(port, (err) => {
server.listen(port, host, (err) => {
if (err) {
return console.log('something bad happened', err)
}

console.log(`server is listening on ${port}`)
console.log(`server is listening on ${host} ${port}`);
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const http = require('http')
const port = process.argv[2]
const host = process.argv[3]

console.log(`DEBUG testing debug log`)
console.log(`WARN testing warn log`)
Expand All @@ -13,6 +14,6 @@ const server = http.createServer((req, res) => {
res.end('OK!');
})

server.listen(port, () => {
console.log(`server is listening on ${port}`)
server.listen(port, host, () => {
console.log(`server is listening on ${host} ${port}`);
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const http = require("http");
const port = process.argv[2];
const host = process.argv[3];

const requestHandler = (request, response) => {
if (request.url === "/status") {
Expand All @@ -17,10 +18,10 @@ const requestHandler = (request, response) => {

const server = http.createServer(requestHandler);

server.listen(port, err => {
server.listen(port, host, err => {
if (err) {
return console.log("something bad happened", err);
}

console.log(`server is listening on ${port}`);
console.log(`server is listening on ${host} ${port}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const http = require('http');
const port = process.argv[2];
const host = process.argv[3];

const requestHandler = (request, response) => {
if (request.url === '/status' || request.url === '/new-tsconfig') {
Expand All @@ -20,10 +21,10 @@ const requestHandler = (request, response) => {

const server = http.createServer(requestHandler);

server.listen(port, (err) => {
server.listen(port, host, (err) => {
if (err) {
return console.log('something bad happened', err)
}

console.log(`server is listening on ${port}`)
console.log(`server is listening on ${host} ${port}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const http = require("http");
const port = process.argv[2];
const host = process.argv[3]

let server;

Expand All @@ -19,12 +20,12 @@ const requestHandler = async (request, response) => {

server = http.createServer(requestHandler);

server.listen(port, err => {
server.listen(port, host, err => {
if (err) {
return console.log("something bad happened", err);
}

console.log(`server is listening on ${port}`);
console.log(`server is listening on ${host} ${port}`);
});

function sleep(ms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const http = require("http");
const port = process.argv[2];
const host = process.argv[3]

const requestHandler = (request, response) => {
if (request.url === "/status") {
Expand All @@ -16,10 +17,10 @@ const requestHandler = (request, response) => {

const server = http.createServer(requestHandler);

server.listen(port, err => {
server.listen(port, host, err => {
if (err) {
return console.log("something bad happened", err);
}

console.log(`server is listening on ${port}`);
console.log(`server is listening on ${host} ${port}`);
});

0 comments on commit 89eaee7

Please sign in to comment.