R
Railwayβ€’3mo ago
Mirsa

assets hosting

How much is fast railway to deliver images does it use cdn or something, i mean is it a good idea to store data in the persistent volume ?
Solution:
finally made it work but under /cdn/ folder next the main domain and not as a subdomain
Jump to solution
118 Replies
Percy
Percyβ€’3mo ago
Project ID: N/A
Mirsa
MirsaOPβ€’3mo ago
N/A
Fragly
Fraglyβ€’3mo ago
Railway doesn't have a CDN, you'll need to have your own CDN layer It's not that slow though, I'm in South Africa and most of my deployments is in US-West and I haven't felt the need to add a CDN layer
Mirsa
MirsaOPβ€’3mo ago
right but the volume is still limited to 5gb right ?
Fragly
Fraglyβ€’3mo ago
Oh yea, on hobby plan it's limited to 5GB You can increase it to 250GB on pro plan though
Mirsa
MirsaOPβ€’3mo ago
oh nice, by the way the pro plan the price is fixed to 25 bucks a month or it's only for the additonal usage ?
Fragly
Fraglyβ€’3mo ago
pro plan is a fixed price of 20 bucks per person in the team plus additional resource usage
Mirsa
MirsaOPβ€’3mo ago
ok so you pay even if your not using 20 bucks of bandwich/resource value ?
Adam
Adamβ€’3mo ago
just want to note, a single volume is 5gb on hobby, up to 50 on pro so you could have multiple volumes if needed, they just have to be on different services
Mirsa
MirsaOPβ€’3mo ago
so 50gb not 250
Adam
Adamβ€’3mo ago
where are you seeing 250?
Fragly
Fraglyβ€’3mo ago
the default is 50GB, it can be increased to 250GB
Mirsa
MirsaOPβ€’3mo ago
Fragly was saying maybe i'm not understanding well
Fragly
Fraglyβ€’3mo ago
it was updated recently i believe
Mirsa
MirsaOPβ€’3mo ago
all right so the bandwith is fast enough and stuff to not even need a cdn tho ?
Fragly
Fraglyβ€’3mo ago
yea, 20 usd per person you have on your railway project and then you also pay for resource usage seperately
Mirsa
MirsaOPβ€’3mo ago
i think i'll start hosting on hobby and when my app will grow and need more i'll pass to pro
Fragly
Fraglyβ€’3mo ago
For me personally I never bother adding a CDN but it'd depend on your project's requirements and scale Sounds good πŸ™‚
Mirsa
MirsaOPβ€’3mo ago
by the way i have something that seems not existing anymore the "credits" based plan
Mirsa
MirsaOPβ€’3mo ago
No description
Fragly
Fraglyβ€’3mo ago
The credits based plan does still exist it just can't be used as an option on pro plan accounts
Mirsa
MirsaOPβ€’3mo ago
oh yeah thats what i was gonna ask, so yeah your still locked to the base hobby plan even if you have enough of credits
Fragly
Fraglyβ€’3mo ago
yea, it's worth noting though that when you get pro plan it'll be seperate from your hobby plan so it's not like you upgrade your hobby plan to turn into a pro plan, you just purchase a pro plan here's what that'd look like:
No description
Fragly
Fraglyβ€’3mo ago
Here you can see a hobby (personal) plan and a pro (team) plan
Mirsa
MirsaOPβ€’3mo ago
ok so like on vercel yeah
Fragly
Fraglyβ€’3mo ago
yea
Mirsa
MirsaOPβ€’3mo ago
Okey then, one last question if you don't mind Do you know any good self hostable service similar to cloudinary (api based hosting assets images, video only needed) with image transform (bluring, resizing) ?
Fragly
Fraglyβ€’3mo ago
I've heard good things about imagekit (never used it before though), you could check that out
Mirsa
MirsaOPβ€’3mo ago
okey, i need something that is plug and play with railway template, and capable of hosting images on the direct volume i'll check that out
Brody
Brodyβ€’3mo ago
for future reference, we can transfer credits from your hobby to pro workspace after you create the pro workspace
Mirsa
MirsaOPβ€’3mo ago
thats cool, ty brody @Fragly Thanks for the help thats very sweet from both of you have a great day πŸ˜„ !
Fragly
Fraglyβ€’3mo ago
Happy to help, you too πŸ™‚
Mirsa
MirsaOPβ€’3mo ago
Sorry, i have a question concerning volume. So i've created a volume with mount path -> /assets So i suppose i can now use it directly like a path static folder so
const ASSETS_PATH = "/assets";
const ASSETS_PATH = "/assets";
and await writeFile to the path. Is it right ? So now i'd like to give those images a subdomain so with nginx i'd probably do a server_name and location root.. The goal is to access the images by going on assets.website.com/images.png But here how can i do that ?
Brody
Brodyβ€’3mo ago
you've answered your own question! you are correct in the first question and the second question, yep that's how you'd write to the volume and nginx or similar is how you'd serve files.
Mirsa
MirsaOPβ€’3mo ago
Isn’t there easier way to do that with cloudflare prixing ? And i've installed nginx in railway. So what i suppose again is that i create a nginx.conf file in my project root folder ?
Mirsa
MirsaOPβ€’3mo ago
Yeah but no, i just found this answer from Brody, -> https://help.railway.app/questions/nixpacks-staticfile-provider-configure-n-f0cd2327 Brody - "Railway does not provide a way to provide an nginx.conf file for the staticfile provider. instead, have railway build your app and then serve it with caddy, example here". Yeah here i'm lost never head of that...
Railway Help Station
Nixpacks Staticfile provider configure NGINX for SPA
My project is a React Vite app with React Router. Railway gets just static file, built by my GitLab CI. They get recognized as the Nixpacks Staticfile type when I deploy them on Railway. Now, how can I add an Nginx config that only adds SPA support. Meaning, all requests should be redirected to /index.html. This is the only configuration I ...
Mirsa
MirsaOPβ€’3mo ago
Project ID : 37fc7b13-e02a-498b-8b9e-6d266d1ccf97 So i've tried Caddyfile + nixpacks deploys are fine but app not accessible 502 bad gateway
{
admin off
auto_https off # Disable automatic HTTPS as Cloudflare handles it
}

baryum.co {
tls {
protocols tls1.2 tls1.3
}
reverse_proxy localhost:3000
}

assets.baryum.co {
tls {
protocols tls1.2 tls1.3
}
root * /assets
file_server
}
{
admin off
auto_https off # Disable automatic HTTPS as Cloudflare handles it
}

baryum.co {
tls {
protocols tls1.2 tls1.3
}
reverse_proxy localhost:3000
}

assets.baryum.co {
tls {
protocols tls1.2 tls1.3
}
root * /assets
file_server
}
Idk what is causing the issue, Public Networking tab seems to be correct and cloudflare looks ok aswell... ok tried everything out with caddyfile so i'm leaving that there i'm finnaly trying this example https://railway.app/template/o3MbZe But still experiencing issues with nginx file not seems to be applied anyway i give up nothing works...
Brody
Brodyβ€’3mo ago
you were close, but you used domains instead of listening on the PORT environment variable. either way, nginx or caddy, doesn't provide you with a way to put media onto the service. if this is all new to you, it might be better to stick with something like cloudinary
Mirsa
MirsaOPβ€’3mo ago
either way, nginx or caddy, doesn't provide you with a way to put media onto the service. I made an endpoint on my sveltekit app that will upload the assets to the volume. i used your create react app example for caddy & nixpack but getting 404 or 502...
Brody
Brodyβ€’3mo ago
you can not attach a single volume to multiple services, so whatever volume you are uploading files to is not the same volume you have hooked up to caddy/nginx
Mirsa
MirsaOPβ€’3mo ago
so it is not possible to have a volume on my service with the caddy in the frontend service and attach it to assets in volume ??
No description
Brody
Brodyβ€’3mo ago
not at the same time, no
Mirsa
MirsaOPβ€’3mo ago
oh :/ There is basically no way then to have a subdomain on the volume while being capable of passing data to it from the frontend ? No way, even with another service/template anything ?
Brody
Brodyβ€’3mo ago
oh there definitely is, just not with what you have setup
Mirsa
MirsaOPβ€’3mo ago
oh well i still need to keep my endpoints and api in my frontend sveltekit app, and if i can use the volume to store persistent data that fit my needs How can i do that ?
Brody
Brodyβ€’3mo ago
I don't think i understand the question, you simply read and write files to the volume at its mount point
Mirsa
MirsaOPβ€’3mo ago
yup, but from what i've understood i need nginx or caddy to be able to rewrite the path to make the subdomain pointing the assets folder
Brody
Brodyβ€’3mo ago
why do you need an assets subdomain?
Mirsa
MirsaOPβ€’3mo ago
since cloudinary isn't not cheap at all for custom domain and usage, i want to keep having good looking urls from my custom domain like ppl have with cdn, images or stuff
Brody
Brodyβ€’3mo ago
then just add assets.domain.com to your railway service
Mirsa
MirsaOPβ€’3mo ago
as custom domain ?
Brody
Brodyβ€’3mo ago
yes
Mirsa
MirsaOPβ€’3mo ago
i did but it serves the app like the main domain does, and it doesn't serve images like assets.domain.com/image.png
Brody
Brodyβ€’3mo ago
1. you need to write the code to not serve your main app on that domain. 2. you need to write the code to serve your assets on that subdomain.
Mirsa
MirsaOPβ€’3mo ago
oh rly after many search i've not found anything explaining that
Brody
Brodyβ€’3mo ago
just write the code to do it
Mirsa
MirsaOPβ€’3mo ago
i'll do some search to discover more on the subject but here now idk where to start, never knew we could do that from the frontend side
Brody
Brodyβ€’3mo ago
did you say you were using sveletkit?
Mirsa
MirsaOPβ€’3mo ago
yup
Brody
Brodyβ€’3mo ago
I assume you are using it in CSR mode?
Mirsa
MirsaOPβ€’3mo ago
had to disable it
Brody
Brodyβ€’3mo ago
why? you would need to be using the node adapter for what you want to achieve
Mirsa
MirsaOPβ€’3mo ago
i manage my website content from a chrome web extensions and i need to pass requests from the browser to access the endpoint
Brody
Brodyβ€’3mo ago
huh are you using the node adapter
Mirsa
MirsaOPβ€’3mo ago
yup automated everything in the browser one click and it's resize + screenshot the website then a form is filled and if submitted it goes on my endpoint secured by api key yes sir
Brody
Brodyβ€’3mo ago
okay then accessing the volume and doing the hostname checks, serving the files, etc, are all going to be done server side
Mirsa
MirsaOPβ€’3mo ago
yes always
Brody
Brodyβ€’3mo ago
okay then I'm not sure why you mentioned client side
Mirsa
MirsaOPβ€’3mo ago
i'm unsure but maybe i don't completely understand everything note-adapter is just an adapter to build the code and stuff not providing a complete standalone backend service like express ?
Brody
Brodyβ€’3mo ago
it enables you to write server side code vs. a client side website
Mirsa
MirsaOPβ€’3mo ago
yup exactly why i use sveltekit with SSR instead of static adapter
Brody
Brodyβ€’3mo ago
then it sounds like you understand what you need to be doing, just don't overthink!
Mirsa
MirsaOPβ€’3mo ago
then yeah i'm missing some knowledge then if i can do all of that from node-adapter
Brody
Brodyβ€’3mo ago
you write the code to do what you want to do
Mirsa
MirsaOPβ€’3mo ago
yeah 🀣 thats my main issue i do overthink everything always
Brody
Brodyβ€’3mo ago
just start typing
Mirsa
MirsaOPβ€’3mo ago
sometimes for lack of knowledge
Brody
Brodyβ€’3mo ago
nah you got this, first things first, create a server side route that returns the given media file
Mirsa
MirsaOPβ€’3mo ago
πŸ‘Œ fine ty brody
Mirsa
MirsaOPβ€’3mo ago
You are right i've never tried this part of svelteit docs https://kit.svelte.dev/docs/adapter-node#custom-server
SvelteKit docs
Node servers β€’ SvelteKit documentation
Brody
Brodyβ€’3mo ago
you don't need a custom server to read files off the volume, but you would likely need it to do the assets subdomain redirection stuff
Mirsa
MirsaOPβ€’3mo ago
yes thats why i created my server.js to rediction concenrant the read files off the volume i still don't know how to do that but i'll do my search
Brody
Brodyβ€’3mo ago
at that point it's just writing JavaScript, easy enough, you got it!
Mirsa
MirsaOPβ€’3mo ago
So i can access the volume data, as simple as going to a direct folder like express.static(path.join(__dirname, "/assets"))(req, res, next); right ?
Brody
Brodyβ€’3mo ago
correct
Mirsa
MirsaOPβ€’3mo ago
one thing, now i have to create a subdomain at cloudflare do i have to add it also in railway ?
Brody
Brodyβ€’3mo ago
yes
Mirsa
MirsaOPβ€’3mo ago
so it's limited to 2 custom domains i have to remove www ?
Brody
Brodyβ€’3mo ago
you first need to add it to railway, and then cloudflare though correct, hobby is limited to two
Mirsa
MirsaOPβ€’3mo ago
yup but by doing this arn't we saying that we want our app to run like "main domain name" to the subdomain ? mhhh actually this works tho so i guess it's not
Brody
Brodyβ€’3mo ago
no lol
Mirsa
MirsaOPβ€’3mo ago
Ok the subdomain works but image delivery looks not
Brody
Brodyβ€’3mo ago
you need to write the code for that
Mirsa
MirsaOPβ€’3mo ago
i did
// Subdomain middleware
app.use((req, res, next) => {
const host = req.hostname;
if (host.startsWith("cdn.")) {
// Check if a specific file is requested
if (req.url === "/" || req.url === "") {
// No specific file requested, redirect to error page
return res.status(404).send("Error: No file specified");
}
// Serve static files from the /assets directory
express.static(path.join(__dirname, "/assets"))(req, res, (err) => {
if (err) {
// If file not found, send a 404 error
res.status(404).send("Error: File not found");
}
});
} else {
next();
}
});
// Subdomain middleware
app.use((req, res, next) => {
const host = req.hostname;
if (host.startsWith("cdn.")) {
// Check if a specific file is requested
if (req.url === "/" || req.url === "") {
// No specific file requested, redirect to error page
return res.status(404).send("Error: No file specified");
}
// Serve static files from the /assets directory
express.static(path.join(__dirname, "/assets"))(req, res, (err) => {
if (err) {
// If file not found, send a 404 error
res.status(404).send("Error: File not found");
}
});
} else {
next();
}
});
Maybe an issue witht the endpoint image location ?
Brody
Brodyβ€’3mo ago
doesnt look like valid code to me
Mirsa
MirsaOPβ€’3mo ago
in test env that works even when launched in production localhost
Brody
Brodyβ€’3mo ago
how do you know there are images in the volume
Mirsa
MirsaOPβ€’3mo ago
actually idk by passing it through my endpoint it return "message": "Images processed and saved successfully", with the url but idk how to actually verify since there is no terminal to access
Brody
Brodyβ€’3mo ago
how do you know you are saving to the correct location
Mirsa
MirsaOPβ€’3mo ago
i suppose from your previous answer, when i asked if by doing await writeFile(path.join(ASSETS_PATH, filename1), image1); it'll write the file to the volume location and folder /assets
Mirsa
MirsaOPβ€’3mo ago
reading this https://www.answeroverflow.com/m/1168623790020886578 "By default, the storage location is set to the storage subdirectory in the root of the volume, but by setting a service variable USE_VOLUME_ROOT to 1 you can opt to use the root of the volume as the storage location instead"
Accessing volume for file upload - Railway
Hello, I'm trying to upload files to my volume to use the files within flowise. I have attached a volume to my service and I have the mount path. I just cant find anything in the docs - examples or such things - on how to access this mount path properly. Maybe somebody could point me in the right direction here?
I have read throug...
Brody
Brodyβ€’3mo ago
what does that have to do with the volume on the sveltekit service though?
Mirsa
MirsaOPβ€’3mo ago
oh i was thinking maybe when i upload my file it's uploading it in the root folder instead of going on the volume ?? maybe i misunderstood
Brody
Brodyβ€’3mo ago
you did, that is specific to the filebrowser service
Mirsa
MirsaOPβ€’3mo ago
meh ok so won't help me tho Ok tried with
app.use("/assets", express.static(path.join(__dirname, "assets")));

app.get("/:file", (req, res) => {
const file = req.params.file;
res.sendFile(path.join(__dirname, "assets", file));
});
app.use("/assets", express.static(path.join(__dirname, "assets")));

app.get("/:file", (req, res) => {
const file = req.params.file;
res.sendFile(path.join(__dirname, "assets", file));
});
But no success
Brody
Brodyβ€’3mo ago
for future reference "no success" is not very helpful
Mirsa
MirsaOPβ€’3mo ago
yeah sorry, i mean after upload success by endpoint i get url "https://cdn.baryum.co/download_1725812650425_800x500.png", But it's not accessible
Brody
Brodyβ€’3mo ago
it's not accessible is also not helpful, as that's a very vague term
Mirsa
MirsaOPβ€’3mo ago
basically idk how i can verify if data is written on volume there is no more information on dashboard so hard to say i still can't figure out if it's a url/middleware problem or path/location
Brody
Brodyβ€’3mo ago
there's metrics on disk usage
Mirsa
MirsaOPβ€’3mo ago
yeah stuff seems to be written, where, when and more idk so i can only suppose that yes stuff is being stored so there is a problem in my middle, the way i am retrieving those assets
No description
Mirsa
MirsaOPβ€’3mo ago
πŸ˜„ still not found out but i won't give up
Solution
Mirsa
Mirsaβ€’3mo ago
finally made it work but under /cdn/ folder next the main domain and not as a subdomain
Brody
Brodyβ€’3mo ago
awesome!
Mirsa
MirsaOPβ€’3mo ago
after 495 commits it works
Mirsa
MirsaOPβ€’3mo ago
i think i'm gonna change the way i upload imgs cuz csrf is kinda bad to be disabled. I still can upload those by base64 raw in the json payload @Brody Ty for your help this can be closed
Brody
Brodyβ€’3mo ago
sounds good!
Want results from more Discord servers?
Add your server