Skip to content

Commit 2ddfb41

Browse files
Nabin OliNabin Oli
authored andcommitted
Docker for frontend is also working
1 parent 4d303ac commit 2ddfb41

4 files changed

Lines changed: 35 additions & 32 deletions

File tree

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ services:
1515
frontend:
1616
build: ./frontend
1717
ports:
18-
- "3000:80" # Map host port 3000 to container port 80
18+
- "3000:3000" # Map host port 3000 to container port 3000
1919
volumes:
2020
- ./frontend:/app
21-
- /app/node_modules
22-
depends_on:
23-
- backend
21+
- /app/node_modules # Avoid overwriting node_modules in the container
22+
23+
# command: npm run start # Use 'npm run build && serve -s build -l 3000' for production

frontend/Dockerfile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Stage 1: Build the application
2-
FROM node:18-alpine AS build
1+
# Use Node.js 18 Alpine as the base image
2+
FROM node:18-alpine
33

44
# Set the working directory in the container
55
WORKDIR /app
@@ -13,17 +13,14 @@ RUN npm install
1313
# Copy the rest of the application code
1414
COPY . .
1515

16-
# Build the React app
16+
# Build the application
1717
RUN npm run build
1818

19-
# Stage 2: Serve the build files using nginx
20-
FROM nginx:alpine
19+
# Install `serve` globally to serve the build files
20+
RUN npm install -g serve
2121

22-
# Copy the build files from the previous stage
23-
COPY --from=build /app/dist /usr/share/nginx/html
22+
# Expose the port your app runs on (default for `serve` is 3000)
23+
EXPOSE 3000
2424

25-
# Expose port 80 (default for nginx)
26-
EXPOSE 80
27-
28-
# Start nginx
29-
CMD ["nginx", "-g", "daemon off;"]
25+
# Serve the build files
26+
CMD ["serve", "-s", "build", "-l", "3000"]

frontend/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Data Catalog App
1+
<!-- # Data Catalog App
22
33
The React frontend is built with [Vite](https://vitejs.dev/).
44
@@ -84,4 +84,7 @@ Runs the React site in production mode, independently from drupal.
8484
8585
To run Cypress tests on a local React-only install of this repo, ensure the app is running at `localhost:3000`. In a separate terminal, use `npx cypress run --config baseUrl="http://localhost:3000"`.
8686
87-
If the frontend is installed within a DKAN site, navigate to the `frontend` folder containing your installation of this repo. Ensure your full site is running, and take note of its URL (PROJECT_NAME.ddev.site), where `PROJECT_NAME` is variable. Run tests using `npx cypress run --config baseUrl="YOUR_DDEV_URL"`, using your project URL for the baseUrl argument
87+
If the frontend is installed within a DKAN site, navigate to the `frontend` folder containing your installation of this repo. Ensure your full site is running, and take note of its URL (PROJECT_NAME.ddev.site), where `PROJECT_NAME` is variable. Run tests using `npx cypress run --config baseUrl="YOUR_DDEV_URL"`, using your project URL for the baseUrl argument -->
88+
89+
npm install\
90+
npm run start

frontend/vite.config.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ import react from '@vitejs/plugin-react';
33

44
export default defineConfig(() => {
55
return {
6-
base: '/',
6+
base: '/', // Ensure this is correct for your deployment environment
77
build: {
8-
outDir: 'build/static',
8+
outDir: 'build', // Change this to 'build' instead of 'build/static'
99
manifest: true,
1010
rollupOptions: {
1111
output: {
12-
entryFileNames: `js/[name].js`,
13-
chunkFileNames: `js/chunks/[name].[hash].js`,
14-
assetFileNames: ({name}) => {
12+
entryFileNames: `assets/[name].js`, // Use 'assets' folder for better organization
13+
chunkFileNames: `assets/chunks/[name].[hash].js`,
14+
assetFileNames: ({ name }) => {
1515
if (/\.css$/.test(name ?? '')) {
16-
return `css/[name].[ext]`;
16+
return `assets/css/[name].[ext]`; // CSS files in 'assets/css'
1717
}
18-
// default value
19-
return 'media/[name].[ext]';
18+
if (/\.(png|jpe?g|gif|svg|webp)$/.test(name ?? '')) {
19+
return `assets/media/[name].[ext]`; // Images in 'assets/media'
20+
}
21+
// Default for other assets
22+
return 'assets/[name].[ext]';
2023
},
2124
},
22-
}
25+
},
2326
},
2427
plugins: [react()],
2528
server: {
@@ -28,8 +31,8 @@ export default defineConfig(() => {
2831
'/api/1': {
2932
target: 'https://demo.getdkan.org',
3033
changeOrigin: true,
31-
}
32-
}
33-
}
34-
}
35-
});
34+
},
35+
},
36+
},
37+
};
38+
});

0 commit comments

Comments
 (0)