(args)
| 28 | const debuggerStaticFile = {}; |
| 29 | |
| 30 | function main(args) { |
| 31 | const port = parseInt(args['port']); |
| 32 | const version = args['version']; |
| 33 | |
| 34 | app.get('/*', (req, res) => { |
| 35 | // Remove leading '/'. |
| 36 | let filePath = req.path.substring(1); |
| 37 | if (filePath === '') { |
| 38 | filePath = 'index.html'; |
| 39 | } |
| 40 | |
| 41 | // Send file from the unzipped tfjs-debugger bundle from memory. |
| 42 | if (debuggerStaticFile[filePath]) { |
| 43 | res.contentType(path.basename(filePath)); |
| 44 | res.send(debuggerStaticFile[filePath]); |
| 45 | } |
| 46 | // Send other files from the local file system. |
| 47 | else { |
| 48 | const tfjsRoot = __dirname.replace('/scripts', '/'); |
| 49 | res.sendFile(tfjsRoot + filePath); |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | app.listen(port, async () => { |
| 54 | // On server start-up, fetch the zipped debugger bundle and unzip in memory. |
| 55 | console.log('Fetching tfjs debugger static files...'); |
| 56 | await fetchAndUnzipTfjsDebuggerBundle(version); |
| 57 | console.log('Done'); |
| 58 | console.log(`Local debugger server started at http://localhost:${ |
| 59 | port}/?bv__0=Local%20build&bv__1=`); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | async function fetchAndUnzipTfjsDebuggerBundle(version) { |
| 64 | let resp; |
no test coverage detected
searching dependent graphs…