| 30 | const BoardThing = require(`./board/${board}`); |
| 31 | |
| 32 | function runServer() { |
| 33 | const port = process.argv[3] ? Number(process.argv[3]) : 8888; |
| 34 | const url = `http://localhost:${port}`; |
| 35 | |
| 36 | log(`Usage:\n\ |
| 37 | ${process.argv[0]} ${process.argv[1]} [board] [port]\n\ |
| 38 | Try:\ncurl -H "Accept: application/json" ${url}\ |
| 39 | \n`); |
| 40 | const thing = new BoardThing(); |
| 41 | const server = new WebThingServer(new SingleThing(thing), port); |
| 42 | process.on('SIGINT', () => { |
| 43 | const cleanup = () => { |
| 44 | thing && thing.close(); |
| 45 | log(`log: board: ${board}: Exit`); |
| 46 | process.exit(); |
| 47 | }; |
| 48 | server.stop().then(cleanup).catch(cleanup); |
| 49 | }); |
| 50 | server.start().catch(console.error); |
| 51 | log(`log: board: ${board}: Started`); |
| 52 | } |
| 53 | |
| 54 | if (module.parent === null) { |
| 55 | runServer(); |