Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 3d09af4

Browse files
committed
feat(serve): Add address and port CLI args for nixster server
1 parent 392203b commit 3d09af4

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

package-lock.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nix.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export function location (env: string): string {
267267
* @param env The environment name
268268
* @param pkgs An array of normalized package names
269269
*/
270-
export async function install (env: string, pkgs: Array<string>, clean: boolean = false, inDocker: boolean = false) {
270+
export async function install (env: string, pkgs: Array<string>, clean: boolean = false) {
271271
let channels: { [key: string]: any } = {}
272272
for (let pkg of pkgs) {
273273
let matches = await match(pkg)
@@ -295,23 +295,7 @@ export async function install (env: string, pkgs: Array<string>, clean: boolean
295295
if (clean) args = args.concat('--remove-all')
296296
args = args.concat('--attr', channels[channel].map((pkg: any) => pkg.attr))
297297

298-
let command
299-
300-
if (inDocker) {
301-
command = 'docker'
302-
let dockerArgs = [
303-
'run',
304-
'stencila/nixster', 'nix-env'
305-
// todo: write correct commands
306-
]
307-
args = dockerArgs.concat(args)
308-
} else {
309-
command = 'nix-env'
310-
}
311-
312-
console.log(args.join(' '))
313-
314-
await spawn(command, args, {
298+
await spawn('nix-env', args, {
315299
stdio: 'inherit'
316300
})
317301
}

src/serve.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import path from 'path'
22
import stream from 'stream'
3+
import yargs from 'yargs'
4+
35

46
import express from 'express'
57

68
import Environment, { SessionParameters, Platform } from './Environment'
79

10+
const DEFAULT_PORT = 3000
11+
12+
let argv = yargs.scriptName('nixster-serve')
13+
.help('h')
14+
.alias('h', 'help')
15+
.option('port', {
16+
alias: 'p',
17+
default: DEFAULT_PORT,
18+
describe: 'Port to listen on',
19+
type: 'number'
20+
})
21+
.option('address', {
22+
alias: 'a',
23+
default: 'localhost',
24+
describe: 'Host address to listen on',
25+
type: 'string'
26+
})
27+
.argv
28+
829
const app = express()
930
const expressWs = require('express-ws')(app)
1031

@@ -15,6 +36,7 @@ app.use(express.static(path.join(__dirname, 'static')))
1536
const jsonParser = require('body-parser').json()
1637
app.use(jsonParser)
1738

39+
1840
// todo: rename shell to interact
1941
// Instantiate shell and set up data handlers
2042
expressWs.app.ws('/shell', async (ws: any, req: express.Request) => {
@@ -75,5 +97,5 @@ expressWs.app.post('/stop', async (req: any, res: any) => {
7597
// req: some JSON -> with container ID that will stop the container
7698
})
7799

78-
app.listen(3000)
79-
console.error('Listening on http://localhost:3000')
100+
app.listen(argv.port, argv.address)
101+
console.info(`Listening on http://${argv.address}:${argv.port}`)

src/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<title>Nixter</title>
4+
<title>Nixster</title>
55
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
66
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
77
<script src="https://unpkg.com/xterm@3.10.1/dist/xterm.js"></script>

0 commit comments

Comments
 (0)