import * as express from "express"; import {Watcher} from "./types/state"; import * as path from "path"; import * as cors from "cors"; export function webappServe(watchers: Watcher[], host = 'localhost', port = 10501) { const webapp = express() webapp.use(cors()) webapp.get('/status', (req, res) => { res.send(watchers.map(watcher => { return { name: watcher.name, state: watcher.state, message: watcher.error, } })) }) webapp.use('/', express.static(path.join(__dirname, '../../dist/'))) webapp.listen(port, host, () => console.log(`webserver listening at http://${host}:${port}`)) }