a year ago
React frontend using 500mb of memory at all times
42 Replies
a year ago
yeah this is a dev server
a year ago
copy the nixpacks.toml and caddyfile from this repo into your repo
a year ago
how does one know if they are using a dev server?
a year 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
a year ago
ohhh
a year ago
its not a railway thing
a year ago
nope
a year ago
makes much more sense
a year ago
in this case, kalon is telling railway to run the dev server since its what their start script is set to
a year ago
you mean you are using a dockerfile?
a year ago
yes you are, send me it please
a year ago
lmao sorry, yes you are using a dockerfile
a year ago
would still use like 60mb
```# Use an official Node.js runtime as a parent image
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"]```
a year ago
enclose in code block please
a year ago
triple backticks
a year ago
one sec
a year 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"]a year ago
you wont need the nixpacks.toml file, but you will need the caddyfile
what's funny is that the other react project is in the same place here but uses a different dockerfile
```# Use an official Node.js runtime as a parent image
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"]
```
a year ago
awsome!
