Skip to content

Commit

Permalink
fix: Not Reconstructing Regexes.
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
  • Loading branch information
whizzzkid committed Oct 25, 2023
1 parent 48f73ef commit fcb2341
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/heliaFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class HeliaFetch {
private fs!: UnixFS
private readonly delegatedRoutingApi: string
private readonly log: debug.Debugger
private readonly PARSE_PATH_REGEX = /^\/(?<namespace>ip[fn]s)\/(?<address>[^/$]+)(?<relativePath>[^$]*)/
private readonly rootFilePatterns: string[]
public node!: Helia
public ready: Promise<void>
Expand Down Expand Up @@ -84,8 +85,7 @@ export class HeliaFetch {
throw new Error('Path is empty')
}
this.log(`Parsing path: ${path}`)
const regex = /^\/(?<namespace>ip[fn]s)\/(?<address>[^/$]+)(?<relativePath>[^$]*)/
const result = path.match(regex)
const result = path.match(this.PARSE_PATH_REGEX)
if (result == null || result?.groups == null) {
this.log(`Error parsing path: ${path}:`, result)
throw new Error(`Path: ${path} is not valid, provide path as /ipfs/<cid> or /ipns/<path>`)
Expand Down
4 changes: 2 additions & 2 deletions src/heliaServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface RouteHandler {
export class HeliaServer {
private heliaFetch!: HeliaFetch
private heliaVersionInfo!: { Version: string, Commit: string }
private readonly HOST_PART_REGEX = /^(?<address>.+)\.(?<namespace>ip[fn]s)\..+$/
private readonly log: debug.Debugger
public isReady: Promise<void>
public routes: RouteEntry[]
Expand Down Expand Up @@ -81,8 +82,7 @@ export class HeliaServer {
* Parses the host into its parts.
*/
private parseHostParts (host: string): { address: string, namespace: string } {
const hostPartsRegex = /^(?<address>.+)\.(?<namespace>ip[fn]s)\..+$/
const result = host.match(hostPartsRegex)
const result = host.match(this.HOST_PART_REGEX)
if (result == null || result?.groups == null) {
this.log(`Error parsing path: ${host}:`, result)
throw new Error(`Subdomain: ${host} is not valid`)
Expand Down

1 comment on commit fcb2341

@SgtPooki
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Please sign in to comment.