(devServerConfig: d.DevServerConfig, incomingReq: IncomingMessage)
| 125 | } |
| 126 | |
| 127 | function normalizeHttpRequest(devServerConfig: d.DevServerConfig, incomingReq: IncomingMessage) { |
| 128 | const req: d.HttpRequest = { |
| 129 | method: (incomingReq.method || 'GET').toUpperCase() as any, |
| 130 | headers: incomingReq.headers as any, |
| 131 | acceptHeader: |
| 132 | (incomingReq.headers && typeof incomingReq.headers.accept === 'string' && incomingReq.headers.accept) || '', |
| 133 | host: (incomingReq.headers && typeof incomingReq.headers.host === 'string' && incomingReq.headers.host) || null, |
| 134 | url: null, |
| 135 | searchParams: null, |
| 136 | }; |
| 137 | |
| 138 | const incomingUrl = (incomingReq.url || '').trim() || null; |
| 139 | if (incomingUrl) { |
| 140 | if (req.host) { |
| 141 | req.url = new URL(incomingReq.url, `http://${req.host}`); |
| 142 | } else { |
| 143 | req.url = new URL(incomingReq.url, `http://dev.stenciljs.com`); |
| 144 | } |
| 145 | req.searchParams = req.url.searchParams; |
| 146 | } |
| 147 | |
| 148 | if (req.url) { |
| 149 | const parts = req.url.pathname.replace(/\\/g, '/').split('/'); |
| 150 | |
| 151 | req.pathname = parts.map((part) => decodeURIComponent(part)).join('/'); |
| 152 | if (req.pathname.length > 0 && !isDevClient(req.pathname)) { |
| 153 | req.pathname = '/' + req.pathname.substring(devServerConfig.basePath.length); |
| 154 | } |
| 155 | |
| 156 | req.filePath = normalizePath(path.normalize(path.join(devServerConfig.root, path.relative('/', req.pathname)))); |
| 157 | } |
| 158 | |
| 159 | return req; |
| 160 | } |
| 161 | |
| 162 | export function isValidHistoryApi(devServerConfig: d.DevServerConfig, req: d.HttpRequest) { |
| 163 | if (!devServerConfig.historyApiFallback) { |
no test coverage detected