Skip to content

Demo - add dockerfile & api route #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:19-alpine
ENV PORT 8080

WORKDIR /usr/src/app

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

RUN apk add --no-cache git
COPY . .
EXPOSE 8080
CMD ["npm", "start", "--no-update-notifier"]
Comment on lines +2 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

You changed the application to run on port 8080 in the Dockerfile. Additionally, the default server port in appConfig.js was changed to 80. These changes are important and should be reflected in the documentation to ensure users know how to start the application correctly and which ports to use.

Example documentation update:

## Running the Application

To start the application, use the following command:

```bash
docker run -p 8080:8080 your-image-name

The application will run on port 8080 by default.

Configuration

The default server port is set to 80. You can override this by setting the PORT environment variable.

Comment on lines +2 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

You changed the application to run on port 8080 in the Dockerfile and modified the default server port to 80 in appConfig.js. This change seems important, so it might be smart to update the documentation accordingly. Make sure to specify the correct port for running the application.

Example documentation update:

### Running the Application

To start the application, use the following command:

```bash
docker run -p 8080:8080 your-image-name

The application will be accessible at http://localhost:8080.

Comment on lines +1 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

Your Dockerfile does not utilize multi-stage builds, which can significantly reduce the final image size and improve build efficiency. Consider restructuring it as follows:

# Stage 1: Build
FROM node:19-alpine AS builder
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .

# Stage 2: Production
FROM node:19-alpine
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app .
EXPOSE 8080
CMD ["npm", "start", "--no-update-notifier"]

(Based on guideline 'Dockerfiles should use multi-stage builds')

2 changes: 1 addition & 1 deletion src/config/appConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Configuration {

serverPort() {
return process.env.PORT || 8080;
return process.env.PORT || 80;
}
logLevel(){
return process.env.LOG_LEVEL || "info";
Expand Down
3 changes: 3 additions & 0 deletions src/routes/exampleRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ const router = express.Router();
router.route("/:id")
.get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById)

router.route("/get/:id").get(exampleController.getById)

Comment on lines +12 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

The route '/get/:id' is missing the grantAccessByPermissionMiddleware, which is essential for proper permission checks. Update the route definition to include this middleware as follows:

+ router.route("/get/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById)

(Based on guideline 'Routes should check permissions')

Comment on lines +12 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

The route '/get/:id' does not implement the grantAccessByPermissionMiddleware function for permission checks. According to the security guidelines, all routes must include this middleware. Update the route as follows:

router.route("/get/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById);

(Based on guideline 'Routes should check permissions')


export default router;
Loading