Ricky01anjay commited on
Commit
c3373d2
·
verified ·
1 Parent(s): 8962ee8

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -20
Dockerfile CHANGED
@@ -1,33 +1,43 @@
1
- # Menggunakan Node.js versi terbaru yang stabil
2
- FROM node:20-slim
3
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
- # Install library langsung tanpa package.json
8
- RUN npm install fast-http-proxy
9
 
10
- # Membuat file server.js secara inline
11
- # Kode ini menangani routing /fetch?url= dan mendukung GET, POST, PUT, DELETE, dll.
12
- RUN echo 'const proxy = require("fast-http-proxy"); \
13
- const http = require("http"); \
14
  const url = require("url"); \
 
 
15
  const server = http.createServer((req, res) => { \
16
- const parsedUrl = url.parse(req.url, true); \
17
- if (parsedUrl.pathname === "/fetch" && parsedUrl.query.url) { \
18
- const target = parsedUrl.query.url; \
19
- proxy(target)(req, res); \
 
 
 
 
 
 
 
 
 
20
  } else { \
21
- res.writeHead(404); \
22
- res.end("Gunakan /fetch?url=http://example.com"); \
23
  } \
24
  }); \
25
- server.listen(7860, "0.0.0.0", () => { \
26
- console.log("Proxy server berjalan di port 7860"); \
27
- });' > server.js
28
 
29
- # Ekspos port yang digunakan Hugging Face (7860)
30
  EXPOSE 7860
31
 
32
- # Jalankan aplikasi
33
- CMD ["node", "server.js"]
 
1
+ # Gunakan image node yang ringan
2
+ FROM node:18-slim
3
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install library http-proxy secara langsung
8
+ RUN npm install http-proxy
9
 
10
+ # Buat file index.js langsung di dalam Dockerfile
11
+ RUN echo 'const http = require("http"); \
12
+ const httpProxy = require("http-proxy"); \
 
13
  const url = require("url"); \
14
+ const proxy = httpProxy.createProxyServer({}); \
15
+ \
16
  const server = http.createServer((req, res) => { \
17
+ const query = url.parse(req.url, true).query; \
18
+ const targetUrl = query.url; \
19
+ \
20
+ if (req.url.startsWith("/fetch") && targetUrl) { \
21
+ console.log(`Proxying ${req.method} request to: ${targetUrl}`); \
22
+ proxy.web(req, res, { \
23
+ target: targetUrl, \
24
+ changeOrigin: true, \
25
+ ignorePath: true \
26
+ }, (e) => { \
27
+ res.writeHead(500); \
28
+ res.end("Proxy Error: " + e.message); \
29
+ }); \
30
  } else { \
31
+ res.writeHead(200, { "Content-Type": "text/plain" }); \
32
+ res.end("Gunakan /fetch?url=https://target-web.com"); \
33
  } \
34
  }); \
35
+ \
36
+ console.log("Server running on port 7860"); \
37
+ server.listen(7860);' > index.js
38
 
39
+ # Expose port standar Hugging Face Spaces
40
  EXPOSE 7860
41
 
42
+ # Jalankan aplikasinya
43
+ CMD ["node", "index.js"]