Skip to content

Commit

Permalink
Fix loading the web interface directly on a /group route
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalle19 committed Feb 17, 2024
1 parent c2aac72 commit 75d539f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IncomingMessage, RequestListener, ServerResponse } from 'http'
import { promises as fsPromisified } from 'fs'

const basePath = __dirname + '/../../webif/build'
const webRoutes = ['/', '/configuration']
const webRoutes = ['/', '/configuration', '/group']

const mimeTypes = new Map<string, string>([
['.html', 'text/html'],
Expand Down Expand Up @@ -39,7 +39,7 @@ const resolveFilePath = (reqUrl: string | undefined): string => {

// "Convert" routes to file path
let filePath
if (!reqUrl || webRoutes.includes(reqUrl)) {
if (!reqUrl || isWebRoute(reqUrl)) {
filePath = '/index.html'
} else {
filePath = reqUrl
Expand All @@ -48,6 +48,16 @@ const resolveFilePath = (reqUrl: string | undefined): string => {
return basePath + filePath
}

const isWebRoute = (reqUrl: string): boolean => {
for (const route of webRoutes) {
if (reqUrl.startsWith(route)) {
return true
}
}

return false
}

const serveStaticFile = async (
filePath: string,
contentType: string | undefined,
Expand Down

0 comments on commit 75d539f

Please sign in to comment.