Skip to content

Commit

Permalink
Add host and port configuration to start-example server and the stand…
Browse files Browse the repository at this point in the history
…alone client (#409)
  • Loading branch information
holkerveen authored Dec 23, 2024
1 parent efa84c4 commit f30c550
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
32 changes: 31 additions & 1 deletion examples/workflow-standalone/scripts/start-example-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ const serverDirPath = path.resolve(__dirname, '..', 'server');
async function run() {
const serverFile = await downloadIfNecessary();
console.log();

const port = parsePortArg();
const host = parseHostArg();

sh.cd(serverDirPath);
sh.exec(`node ${serverFile} -w -p 8081`);
sh.exec(`node ${serverFile} -w --port ${port} --host ${host}`);
}

async function downloadIfNecessary(): Promise<string> {
Expand Down Expand Up @@ -72,4 +76,30 @@ async function downloadIfNecessary(): Promise<string> {
return `${config.fileName}-${version}.js`;
}

function parsePortArg(): number {
let port = 8081;
const portIndex = process.argv.indexOf('--port');
if (portIndex >= 0) {
port = parseInt(process.argv[portIndex + 1]);
}
if(isNaN(port)) {
console.error('Invalid port number');
process.exit(1);
}
return port;
}

function parseHostArg(): string {
let host = 'localhost';
const hostIndex = process.argv.indexOf('--host');
if(hostIndex >= 0) {
host = process.argv[hostIndex + 1];
}
if(typeof host !== 'string') {
console.error('Invalid host');
process.exit(1);
}
return host;
}

run();
5 changes: 3 additions & 2 deletions examples/workflow-standalone/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import { Container } from 'inversify';
import { join, resolve } from 'path';
import { MessageConnection } from 'vscode-jsonrpc';
import createContainer from './di.config';
const port = 8081;
const host = GLSP_SERVER_HOST;
const port = GLSP_SERVER_PORT;
const id = 'workflow';
const diagramType = 'workflow-diagram';

Expand All @@ -37,7 +38,7 @@ const currentDir = loc.substring(0, loc.lastIndexOf('/'));
const examplePath = resolve(join(currentDir, '../app/example1.wf'));
const clientId = 'sprotty';

const webSocketUrl = `ws://localhost:${port}/${id}`;
const webSocketUrl = `ws://${host}:${port}/${id}`;

let glspClient: GLSPClient;
let container: Container;
Expand Down
2 changes: 2 additions & 0 deletions examples/workflow-standalone/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const GLSP_SERVER_HOST: string;
declare const GLSP_SERVER_PORT: string;
6 changes: 5 additions & 1 deletion examples/workflow-standalone/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ module.exports = {
new webpack.ProvidePlugin({
process: 'process/browser'
}),
new webpack.WatchIgnorePlugin({ paths: [/\.js$/, /\.d\.ts$/] })
new webpack.WatchIgnorePlugin({ paths: [/\.js$/, /\.d\.ts$/] }),
new webpack.DefinePlugin({
GLSP_SERVER_HOST: JSON.stringify(process.env.GLSP_SERVER_HOST || 'localhost'),
GLSP_SERVER_PORT: JSON.stringify(process.env.GLSP_SERVER_PORT || '8081'),
})
]
};

0 comments on commit f30c550

Please sign in to comment.