Skip to content

In Dev Mode, localhost:5173/api returns 404 instead of :8090/api returning json. #1218

Description

@rainbowforgedev

Dev Mode Bug Report (only relevant to developers, not users)

Issue Description

When attempting to modify primo cms core by following the steps outlined in developers.md, the cms fails to load at the live preview app. As stated in the title, in Dev Mode, localhost:5173 API calls appear to be sent to localhost:5173/api instead of localhost:8090/api as expected.

Reproduction

First, follow the instructions for developers to begin modifying primo core https://github.com/rainbowforgedev/primo/blob/main/DEVELOPERS.md.

(make sure to add git-hooks to devenv inputs if not done already)

  devenv inputs add git-hooks github:cachix/git-hooks.nix

Then, attempt to launch localhost:5173. You should see the loader spin infinitely, and in console a 404 error for: http://localhost:5173/api/primo/info.

Potential Fix

I have a potential fix for this issue by modifying instances.ts as follows:

Original /src/lib/pocketbase/instances.ts

import PocketBase from 'pocketbase'

const marketplace_url = import.meta.env.VITE_MARKETPLACE_URL || 'https://main.marketplace.primo.page'

export const self = new PocketBase(typeof location !== 'undefined' ? location.origin : 'http://127.0.0.1:3000')
export const marketplace = new PocketBase(marketplace_url)

Suggested Modified /src/lib/pocketbase/instances.ts

import PocketBase from 'pocketbase'
const marketplace_url = import.meta.env.VITE_MARKETPLACE_URL || 'https://main.marketplace.primo.page'
const getPBUrl = () => {                    
  if (typeof location === 'undefined') return 'http://127.0.0.1:3000'                                   
  if (location.port === '5173') {                                                                  
    return 'http://localhost:8090' //                                                                   
  }                                                               
  return location.origin                                                                             
}                          
export const self = new PocketBase(getPBUrl())                                                        
export const marketplace = new PocketBase(marketplace_url)

Alternative Potential Fixes

Using PDM env var

Currently, changing PRIMO_DEV_MODE in devenv.nix does not seem to fix this issue either. Perhaps an alternative fix could be to use that env variable and only use the modified instances.ts file when PRIMO_DEV_MODE is set to 1? Unless I'm misunderstanding the purpose of that env variable?

Changing documentation

Or perhaps it's easier to just update the documentation and update developers.md to reflect the steps needed to be taken in order to get a functioning live preview environment of Primo? There's also the other potentially helpful note of adding git-hooks that could be added to developers.md as well?

Conclusion

Please let me know if any further information is required, or if I made any mistakes or anything else I should know; I'm very new to this 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions