React with router getting 404

I know it's a common knowledge where SPAs are getting 404 if used in combination with routing solution, however it seems that some people were able to fix it, but not my case unfortunately. I followed steps advised in this thread - https://discord.com/channels/713503345364697088/1019596063079944273 but now I am just getting Server Error from Railway when trying to access the webapp and there are no logs in the Deployment logs at all. My Dockerfile
FROM node:18-alpine AS builder

ARG PORT

# Add a work directory
WORKDIR /app

COPY package.json .

RUN npm install

COPY . /app/

RUN npm run build

FROM nginx:1.19.10-alpine

# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html

# Remove default nginx static assets
RUN rm -rf ./*

COPY --from=builder /app/build .

COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 3000

ENTRYPOINT ["nginx", "-g", "daemon off;"]
FROM node:18-alpine AS builder

ARG PORT

# Add a work directory
WORKDIR /app

COPY package.json .

RUN npm install

COPY . /app/

RUN npm run build

FROM nginx:1.19.10-alpine

# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html

# Remove default nginx static assets
RUN rm -rf ./*

COPY --from=builder /app/build .

COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 3000

ENTRYPOINT ["nginx", "-g", "daemon off;"]
And .nginx/nginx.conf file
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}
I am not even sure how to troubleshoot this as it seems like i am not hitting the webapp at all as there are no logs? Any help would be appreciated
7 Replies
Percy
Percy2y ago
Project ID: bef41c2c-b1a9-42ef-adb9-e3afa84fbbea
IamIconLiving
IamIconLivingOP2y ago
bef41c2c-b1a9-42ef-adb9-e3afa84fbbea
Brody
Brody2y ago
set listen to 8080, and then set a service variable PORT = 8080
IamIconLiving
IamIconLivingOP2y ago
do you mean in vite config set server to listen on 8080 as opposed to 3000?
Brody
Brody2y ago
you are using nginx is this a csr app?
IamIconLiving
IamIconLivingOP2y ago
wow yes, this exactly did the trick! listening to 8080 and setting ports in env variable! thank you!
Brody
Brody2y ago
no problem!
Want results from more Discord servers?
Add your server