Skip to content

Commit

Permalink
fix: memory leak while downloading large files
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 9, 2023
1 parent 3891900 commit 97e7d71
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Expand Up @@ -32,7 +32,9 @@ ENV NODE_ENV=docker
# Alpine specific dependencies
RUN apk update --no-cache
RUN apk upgrade --no-cache
RUN apk add --no-cache curl
RUN apk add --no-cache curl nginx

COPY ./nginx/nginx.conf /etc/nginx/nginx.conf

WORKDIR /opt/app/frontend
COPY --from=frontend-builder /opt/app/public ./public
Expand All @@ -55,4 +57,4 @@ HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:3000/api/he

# Application startup
# HOSTNAME=0.0.0.0 fixes https://github.com/vercel/next.js/issues/51684. It can be removed as soon as the issue is fixed
CMD cp -rn /tmp/img /opt/app/frontend/public && HOSTNAME=0.0.0.0 node frontend/server.js & cd backend && npm run prod
CMD cp -rn /tmp/img /opt/app/frontend/public && nginx && PORT=3333 HOSTNAME=0.0.0.0 node frontend/server.js & cd backend && npm run prod
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -63,6 +63,8 @@ npm run build
pm2 start --name="pingvin-share-frontend" npm -- run start
```

**Uploading Large Files**: By default, Pingvin Share uses a built-in reverse proxy to reduce the installation steps. However, this reverse proxy is not optimized for uploading large files. If you wish to upload larger files, you can either use the Docker installation or set up your own reverse proxy. An example configuration for Nginx can be found in `/nginx/nginx.conf`.

The website is now listening on `http://localhost:3000`, have fun with Pingvin Share 🐧!

### Integrations
Expand Down
19 changes: 19 additions & 0 deletions backend/src/app.controller.ts
@@ -0,0 +1,19 @@
import { Controller, Get, Res } from "@nestjs/common";
import { Response } from "express";
import { PrismaService } from "./prisma/prisma.service";

@Controller("/")
export class AppController {
constructor(private prismaService: PrismaService) {}

@Get("health")
async health(@Res({ passthrough: true }) res: Response) {
try {
await this.prismaService.config.findMany();
return "OK";
} catch {
res.statusCode = 500;
return "ERROR";
}
}
}
4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Expand Up @@ -14,6 +14,7 @@ import { ShareModule } from "./share/share.module";
import { UserModule } from "./user/user.module";
import { ClamScanModule } from "./clamscan/clamscan.module";
import { ReverseShareModule } from "./reverseShare/reverseShare.module";
import { AppController } from "./app.controller";

@Module({
imports: [
Expand All @@ -33,6 +34,9 @@ import { ReverseShareModule } from "./reverseShare/reverseShare.module";
ClamScanModule,
ReverseShareModule,
],
controllers:[
AppController,
],
providers: [
{
provide: APP_GUARD,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/api/[...all].tsx
Expand Up @@ -11,6 +11,8 @@ export const config = {

const { apiURL } = getConfig().serverRuntimeConfig;

// A proxy to the API server only used in development.
// In production this route gets overridden by nginx.
export default (req: NextApiRequest, res: NextApiResponse) => {
httpProxyMiddleware(req, res, {
headers: {
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/pages/api/health.tsx

This file was deleted.

22 changes: 22 additions & 0 deletions nginx/nginx.conf
@@ -0,0 +1,22 @@
events {}

http {
server {
listen 3000;
client_max_body_size 100M;

location /api {
proxy_pass http://localhost:8080;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
proxy_pass http://localhost:3333;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

0 comments on commit 97e7d71

Please sign in to comment.