2 years ago
React frontend using 500mb of memory at all times
42 Replies
2 years ago
yeah this is a dev server
2 years ago
copy the nixpacks.toml and caddyfile from this repo into your repo
2 years ago
how does one know if they are using a dev server?
2 years ago
for this, i looked at the start command - react-scripts start
and that starts a dev server, thus, you are running a development server
2 years ago
ohhh
2 years ago
its not a railway thing
2 years ago
nope
2 years ago
makes much more sense
2 years ago
in this case, kalon is telling railway to run the dev server since its what their start script is set to
2 years ago
you mean you are using a dockerfile?
2 years ago
yes you are, send me it please
2 years ago
lmao sorry, yes you are using a dockerfile
2 years ago
would still use like 60mb
FROM node:20
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy the project files
COPY . .
# Build the app
RUN npm run build
# Expose the port the app runs on
EXPOSE 5000
# Start the app using a simple Node server with a fallback
CMD ["npx", "serve", "-s", "build", "-l", "3000"]```
2 years ago
enclose in code block please
2 years ago
triple backticks
2 years ago
one sec
2 years ago
try this -
# Use an official Node.js runtime as a parent image
FROM node:20 AS builder
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy the project files
COPY . ./
# Build the app
RUN npm run build
# Use the latest Caddy image
FROM caddy:latest
# Set the working directory
WORKDIR /app
# Copy the Caddyfile
COPY Caddyfile ./Caddyfile
# Format the Caddyfile
RUN caddy fmt Caddyfile --overwrite
# Copy the build files
COPY --from=builder /app/build ./build
# Start the app using Caddy
CMD ["caddy", "run", "--config", "Caddyfile", "--adapter", "caddyfile"]2 years ago
you wont need the nixpacks.toml file, but you will need the caddyfile
it's active now, i'll just wait and see if the memory usage goes down
what's funny is that the other react project is in the same place here but uses a different dockerfile
FROM node:20
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy the project files
COPY . .
# Build the TypeScript code
RUN npm run build
# Expose the port the app runs on
EXPOSE 3000
# Start the app
CMD ["npm", "start"]2 years ago
awsome!
