(urlPath)
| 18 | const WEB_ROOT = path.resolve(__dirname, '..', 'web'); |
| 19 | |
| 20 | function resolveStaticFilePath(urlPath) { |
| 21 | let decodedPath; |
| 22 | try { |
| 23 | decodedPath = decodeURIComponent(urlPath || '/'); |
| 24 | } catch { |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | const relativePath = decodedPath === '/' |
| 29 | ? 'index.html' |
| 30 | : decodedPath.replace(/^\/+/, ''); |
| 31 | const filePath = path.resolve(WEB_ROOT, relativePath); |
| 32 | const relativeToRoot = path.relative(WEB_ROOT, filePath); |
| 33 | |
| 34 | if ( |
| 35 | relativeToRoot.startsWith('..') || |
| 36 | path.isAbsolute(relativeToRoot) |
| 37 | ) { |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | return filePath; |
| 42 | } |
| 43 | |
| 44 | function createHttpServer() { |
| 45 | return http.createServer((req, res) => { |
no outgoing calls
no test coverage detected