davwheat / rail-announcements

Compilation of railway announcement snippets and a website to generate your own announcement snippets.
https://railannouncements.co.uk
MIT License
44 stars 21 forks source link

[Development] Issue with developing locally #229

Closed opott closed 4 months ago

opott commented 5 months ago

When I have tried to add new audio files to the site, I noticed that I get an error when I attempt to test an announcement with the audio snippet that I added.

From what I can gather, it's because the site is programmed to get the files from a CDN, which obviously doesn't contain the files that I'm adding.

Could anyone advise me on a way around this for local development and testing?

davwheat commented 5 months ago

I'll try to look into a fix for this... Essentially, builds were taking far too long on Cloudflare and I was also worried about hitting storage and file count limitations on Cloudflare Pages, hence moving the audio to separate storage.

You might be able to use something like Python's simple web server by running it in the audio/ folder and updating the audio URL prefix in the source code for now.

cd audio
python3 -m http.server 9000

Then update the following lines:

https://github.com/davwheat/rail-announcements/blob/d9a3ac73be2c40e4abd77a7a7c87c9d9200fc795/src/announcement-data/AnnouncementSystem.ts#L153-L155

to:

  generateAudioFileUrl(fileId: string, customPrefix?: string): string {
    return `http://localhost:9000/${customPrefix || this.FILE_PREFIX}/${this.processAudioFileId(fileId).replace(/\./g, '/')}.mp3`
  }
opott commented 5 months ago

@davwheat Just tried your suggested fix, but no luck.

I get this error on the site: image

And this error in the Python terminal:

@opott ➜ /workspaces/rail-announcements/audio (main) $ python3 -m http.server 9000
Serving HTTP on 0.0.0.0 port 9000 (http://0.0.0.0:9000/) ...
127.0.0.1 - - [16/Jun/2024 12:32:11] code 501, message Unsupported method ('OPTIONS')
127.0.0.1 - - [16/Jun/2024 12:32:11] "OPTIONS /SN/377/bing%20bong.mp3 HTTP/1.1" 501 -
127.0.0.1 - - [16/Jun/2024 12:32:11] code 501, message Unsupported method ('OPTIONS')
127.0.0.1 - - [16/Jun/2024 12:32:11] "OPTIONS /SN/377/stations/ABW.mp3 HTTP/1.1" 501 -
127.0.0.1 - - [16/Jun/2024 12:32:11] code 501, message Unsupported method ('OPTIONS')
127.0.0.1 - - [16/Jun/2024 12:32:11] "OPTIONS /SN/377/please%20mind%20the%20gap%20between%20the%20train%20and%20the%20platform.mp3 HTTP/1.1" 501 -
127.0.0.1 - - [16/Jun/2024 12:32:11] code 501, message Unsupported method ('OPTIONS')
127.0.0.1 - - [16/Jun/2024 12:32:11] "OPTIONS /SN/377/we%20are%20now%20approaching.mp3 HTTP/1.1" 501 -
davwheat commented 4 months ago

Sorry this took so long... This should be better now from changes in 9313af4cfc4eca0f1c7ab5488eba3c06b05dc21e and 58ee9b5ef018dffc67f6a149d187161237b71020.

I've added some new info to the README for local development. In a nutshell, run these three in different terminals one after the other:

yarn develop
yarn develop:workers
yarn serve-audio

You can access the site on http://local.davw.network:8787 (local.davw.network points to 127.0.0.1 and is needed for CORS stuff)

Let me know if you still have issues.

opott commented 4 months ago

Hi. Not sure if I am doing something wrong here, but when I follow the steps provided and access the site, I get an error when I open a page for an announcement system. image

However, the Celia & Phil pages appear to work properly, as well as the live trains. I am only having issues opening the pages for onboard systems and the ScotRail station system.

davwheat commented 4 months ago

Oh, I just broke something with my latest change. Not your fault...

opott commented 4 months ago

Oh, that's alright. I thought I was doing something wrong! 😂

davwheat commented 4 months ago

That should also be fixed with the latest commit