* Requests handler * @param {object} req * @param {string} req.requestId * @param {string} req.path
(req)
| 181 | * @param {string} req.path |
| 182 | */ |
| 183 | function handleRequest(req) { |
| 184 | const reqId = req.requestId; |
| 185 | let reqPath = req.path.substring(1); |
| 186 | |
| 187 | if (!reqPath || reqPath.endsWith("/")) { |
| 188 | reqPath += "index.html"; |
| 189 | } |
| 190 | |
| 191 | const ext = Url.extname(reqPath); |
| 192 | let url = null; |
| 193 | |
| 194 | switch (reqPath) { |
| 195 | case CONSOLE_SCRIPT: |
| 196 | if ( |
| 197 | isConsole || |
| 198 | appSettings.value.console === appSettings.CONSOLE_LEGACY |
| 199 | ) { |
| 200 | url = `${ASSETS_DIRECTORY}/build/console.js`; |
| 201 | } else { |
| 202 | url = `${DATA_STORAGE}/eruda.js`; |
| 203 | } |
| 204 | sendFileContent(url, reqId, "application/javascript"); |
| 205 | break; |
| 206 | |
| 207 | case EXECUTING_SCRIPT: { |
| 208 | const text = activeFile?.session?.doc?.toString() || ""; |
| 209 | sendText(text, reqId, "application/javascript"); |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | case MARKDOWN_STYLE: |
| 214 | url = appSettings.value.markdownStyle; |
| 215 | if (url) sendFileContent(url, reqId, "text/css"); |
| 216 | else sendText("img {max-width: 100%;}", reqId, "text/css"); |
| 217 | break; |
| 218 | |
| 219 | default: |
| 220 | sendByExt(); |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | async function sendByExt() { |
| 225 | if (isConsole) { |
| 226 | if (reqPath === "console.html") { |
| 227 | sendText( |
| 228 | mustache.render($_console, { |
| 229 | CONSOLE_SCRIPT, |
| 230 | EXECUTING_SCRIPT, |
| 231 | }), |
| 232 | reqId, |
| 233 | MIMETYPE_HTML, |
| 234 | ); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (reqPath === "favicon.ico") { |
| 239 | sendIco(ASSETS_DIRECTORY, reqId); |
| 240 | return; |
nothing calls this directly
no test coverage detected