R
Railway•8mo 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•8mo ago
Project ID: N/A
Brody
Brody•8mo ago
there is not, your app has to do the redirects itself are you deploying a single page app?
MomsSpaghetti
MomsSpaghetti•8mo 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•8mo ago
whats your stack?
MomsSpaghetti
MomsSpaghetti•8mo ago
Got it to work on netlify. Just checking if railway can do it vue with vue router
Brody
Brody•8mo ago
railway can, the app you deploy still has to handle the redirects whats your bundler?
MomsSpaghetti
MomsSpaghetti•8mo ago
vite
Brody
Brody•8mo ago
do you have any build or start commands set in the service settings?
MomsSpaghetti
MomsSpaghetti•8mo 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•8mo ago
so your dist folder is in your repo?
MomsSpaghetti
MomsSpaghetti•8mo ago
yep couldn't really figure out how to both build and serve
Brody
Brody•8mo ago
remove it and then gitignore it
MomsSpaghetti
MomsSpaghetti•8mo ago
since after the build it is just static html
Brody
Brody•8mo ago
would you happen to have node_modules in your repo too?
MomsSpaghetti
MomsSpaghetti•8mo ago
i am not that stupid
Brody
Brody•8mo ago
dont worry ill get you sorted, trust the process so no build or start commands in the service settings?
MomsSpaghetti
MomsSpaghetti•8mo ago
yaah
Brody
Brody•8mo ago
(yes/no)
MomsSpaghetti
MomsSpaghetti•8mo ago
?
Brody
Brody•8mo ago
yeah is kinda inclusive, im looking for a simple yes/no answer lol
MomsSpaghetti
MomsSpaghetti•8mo ago
bruh YES
Brody
Brody•8mo ago
remove them
MomsSpaghetti
MomsSpaghetti•8mo ago
I have no build or start command in the service setting
Brody
Brody•8mo ago
has the dist folder been gitignored and removed from the repo?
MomsSpaghetti
MomsSpaghetti•8mo ago
yep removed
Brody
Brody•8mo ago
do you have a nixpacks.toml file?
MomsSpaghetti
MomsSpaghetti•8mo ago
no
Brody
Brody•8mo ago
does your package.json have a build script?
MomsSpaghetti
MomsSpaghetti•8mo ago
yes
Solution
Brody
Brody•8mo 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
MomsSpaghetti•8mo ago
hold on. lemmi done
Brody
Brody•8mo ago
push the changes
MomsSpaghetti
MomsSpaghetti•8mo ago
error during build
MomsSpaghetti
MomsSpaghetti•8mo ago
No description
MomsSpaghetti
MomsSpaghetti•8mo ago
am i missing something?
Brody
Brody•8mo ago
does vite not build to dist?
MomsSpaghetti
MomsSpaghetti•8mo ago
it does build to dist
MomsSpaghetti
MomsSpaghetti•8mo ago
oh wait maybe the build is finished before caddy runs
Brody
Brody•8mo ago
you have a Staticfile right?
MomsSpaghetti
MomsSpaghetti•8mo ago
yaah yes*
Brody
Brody•8mo ago
delete it, you want this to be detected as a node app
MomsSpaghetti
MomsSpaghetti•8mo ago
No description
MomsSpaghetti
MomsSpaghetti•8mo ago
its not letting me now
Brody
Brody•8mo ago
do you have a Staticfile in your repo?
MomsSpaghetti
MomsSpaghetti•8mo ago
what are you reffering to ? Do i have Staticfile provider set in nixpack config?
Brody
Brody•8mo ago
literally a file called Staticfile lol
MomsSpaghetti
MomsSpaghetti•8mo ago
no
Brody
Brody•8mo 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
MomsSpaghetti•8mo 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•8mo ago
its a bug
MomsSpaghetti
MomsSpaghetti•8mo ago
Its still says StaticFile tho
MomsSpaghetti
MomsSpaghetti•8mo ago
No description
Brody
Brody•8mo ago
did you push the changes to your repo with that new nixpacks.toml file?
MomsSpaghetti
MomsSpaghetti•8mo ago
yaah i did
Brody
Brody•8mo ago
did the build fail
MomsSpaghetti
MomsSpaghetti•8mo 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•8mo ago
okay big bug, delete service and deploy a new service 🙂
MomsSpaghetti
MomsSpaghetti•8mo ago
Ah lemmi It works!. Lets goo Thanks brody for the help
Brody
Brody•8mo ago
no problem 🙂
MomsSpaghetti
MomsSpaghetti•8mo ago
Do i have to close the issue or does it close on its own?