R
Railway•14mo ago
MomsSpaghetti

How to redirect in railway config

Is there way to configure redirects in railway same way how netlify does? netlify.toml
[build.environment]
NODE_VERSION = "16"

[build]
publish = "dist"
command = "pnpm run build"

[[redirects]]
from = "/*"
to = "/index.html"
status = 200
[build.environment]
NODE_VERSION = "16"

[build]
publish = "dist"
command = "pnpm run build"

[[redirects]]
from = "/*"
to = "/index.html"
status = 200
Solution:
https://github.com/brody192/vue-3-template you shoud be able to copy the nixpacks.toml and Caddyfile from this repo into yours...
Jump to solution
62 Replies
Percy
Percy•14mo ago
Project ID: N/A
Brody
Brody•14mo ago
there is not, your app has to do the redirects itself are you deploying a single page app?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yaah. I been having routing in client side. Hitting an issue where the default nginx config doesn't recognizes the client route and throws 404 when reloaded or visited externally to a specific route other than root of the site. Want to configure it to redirect to the index.html with the requested route instead
Brody
Brody•14mo ago
whats your stack?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
Got it to work on netlify. Just checking if railway can do it vue with vue router
Brody
Brody•14mo ago
railway can, the app you deploy still has to handle the redirects whats your bundler?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
vite
Brody
Brody•14mo ago
do you have any build or start commands set in the service settings?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
I just build locally and deploy. Having staticFile provider config on railway and root directory pointed to the locally built dist directory
Brody
Brody•14mo ago
so your dist folder is in your repo?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yep couldn't really figure out how to both build and serve
Brody
Brody•14mo ago
remove it and then gitignore it
MomsSpaghetti
MomsSpaghettiOP•14mo ago
since after the build it is just static html
Brody
Brody•14mo ago
would you happen to have node_modules in your repo too?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
i am not that stupid
Brody
Brody•14mo ago
dont worry ill get you sorted, trust the process so no build or start commands in the service settings?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yaah
Brody
Brody•14mo ago
(yes/no)
MomsSpaghetti
MomsSpaghettiOP•14mo ago
?
Brody
Brody•14mo ago
yeah is kinda inclusive, im looking for a simple yes/no answer lol
MomsSpaghetti
MomsSpaghettiOP•14mo ago
bruh YES
Brody
Brody•14mo ago
remove them
MomsSpaghetti
MomsSpaghettiOP•14mo ago
I have no build or start command in the service setting
Brody
Brody•14mo ago
has the dist folder been gitignored and removed from the repo?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yep removed
Brody
Brody•14mo ago
do you have a nixpacks.toml file?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
no
Brody
Brody•14mo ago
does your package.json have a build script?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yes
Solution
Brody
Brody•14mo ago
https://github.com/brody192/vue-3-template you shoud be able to copy the nixpacks.toml and Caddyfile from this repo into yours
MomsSpaghetti
MomsSpaghettiOP•14mo ago
hold on. lemmi done
Brody
Brody•14mo ago
push the changes
MomsSpaghetti
MomsSpaghettiOP•14mo ago
error during build
MomsSpaghetti
MomsSpaghettiOP•14mo ago
No description
MomsSpaghetti
MomsSpaghettiOP•14mo ago
am i missing something?
Brody
Brody•14mo ago
does vite not build to dist?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
it does build to dist
MomsSpaghetti
MomsSpaghettiOP•14mo ago
oh wait maybe the build is finished before caddy runs
Brody
Brody•14mo ago
you have a Staticfile right?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yaah yes*
Brody
Brody•14mo ago
delete it, you want this to be detected as a node app
MomsSpaghetti
MomsSpaghettiOP•14mo ago
No description
MomsSpaghetti
MomsSpaghettiOP•14mo ago
its not letting me now
Brody
Brody•14mo ago
do you have a Staticfile in your repo?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
what are you reffering to ? Do i have Staticfile provider set in nixpack config?
Brody
Brody•14mo ago
literally a file called Staticfile lol
MomsSpaghetti
MomsSpaghettiOP•14mo ago
no
Brody
Brody•14mo ago
# https://nixpacks.com/docs/configuration/file

providers = ['node']

# set up some variables to minimize annoyance
[variables]
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
CADDY_VERSION = '2.7.4' # specify the caddy version to use here, without a 'v' prefix. https://github.com/caddyserver/caddy/releases

# download and untar caddy
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"', # download the caddy release specified by 'CADDY_VERSION' from GitHub
'tar -zxvf caddy.tar.gz caddy', # only extract 'caddy' from the tarball
'chmod +x caddy' # enable file execution for caddy, needed to execute downloaded files
]

# format the Caddyfile with fmt
[phases.fmt]
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
cmds = ['caddy fmt --overwrite Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies

# copy caddy and build artifacts to a new image and start the caddy web server
[start]
runImage = 'ubuntu:20.04' # use a new ubuntu image to run the caddy server in
onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist'] # copy only the needed files and folders into the new image (Vite builds to a 'dist' folder)
cmd = './caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
# https://nixpacks.com/docs/configuration/file

providers = ['node']

# set up some variables to minimize annoyance
[variables]
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
CADDY_VERSION = '2.7.4' # specify the caddy version to use here, without a 'v' prefix. https://github.com/caddyserver/caddy/releases

# download and untar caddy
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"', # download the caddy release specified by 'CADDY_VERSION' from GitHub
'tar -zxvf caddy.tar.gz caddy', # only extract 'caddy' from the tarball
'chmod +x caddy' # enable file execution for caddy, needed to execute downloaded files
]

# format the Caddyfile with fmt
[phases.fmt]
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
cmds = ['caddy fmt --overwrite Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies

# copy caddy and build artifacts to a new image and start the caddy web server
[start]
runImage = 'ubuntu:20.04' # use a new ubuntu image to run the caddy server in
onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist'] # copy only the needed files and folders into the new image (Vite builds to a 'dist' folder)
cmd = './caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
use that instead
MomsSpaghetti
MomsSpaghettiOP•14mo ago
ah so it needs the providers array in the config for me to able to edit from UI i didn't have any providers set in the nixpacks config before
Brody
Brody•14mo ago
its a bug
MomsSpaghetti
MomsSpaghettiOP•14mo ago
Its still says StaticFile tho
MomsSpaghetti
MomsSpaghettiOP•14mo ago
No description
Brody
Brody•14mo ago
did you push the changes to your repo with that new nixpacks.toml file?
MomsSpaghetti
MomsSpaghettiOP•14mo ago
yaah i did
Brody
Brody•14mo ago
did the build fail
MomsSpaghetti
MomsSpaghettiOP•14mo ago
the button to add new providers also appeared but got hidden after awhile. I didn't press anything yes the build failed with the same error Its not able to switch to node provider. Still set to Staticfile I have verified that the changes have been pushed as well
Brody
Brody•14mo ago
okay big bug, delete service and deploy a new service 🙂
MomsSpaghetti
MomsSpaghettiOP•14mo ago
Ah lemmi It works!. Lets goo Thanks brody for the help
Brody
Brody•14mo ago
no problem 🙂
MomsSpaghetti
MomsSpaghettiOP•14mo ago
Do i have to close the issue or does it close on its own?
Want results from more Discord servers?
Add your server