kylsprt commited on
Commit
18ca829
·
verified ·
1 Parent(s): b7a6af9

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +46 -0
Dockerfile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:18-alpine
2
+
3
+ RUN apk add --no-cache git
4
+
5
+ RUN git clone https://github.com/schlagmichdoch/PairDrop.git /app && \
6
+ cd /app && npm install
7
+
8
+ RUN mkdir -p /gw && cd /gw && npm install http-proxy
9
+
10
+ RUN cat > /gw/gateway.js << 'GWEOF'
11
+ var http = require('http');
12
+ var httpProxy = require('http-proxy');
13
+ var DOMAIN = process.env.DOMAIN || '';
14
+ var proxy = httpProxy.createProxyServer({ target: 'http://127.0.0.1:3001', ws: true });
15
+ proxy.on('error', function(e, req, res) {
16
+ if (res && res.writeHead) { res.writeHead(502); res.end('502'); }
17
+ });
18
+ function ok(req) {
19
+ if (!DOMAIN) return true;
20
+ var h = (req.headers['x-real-domain'] || '') + '|' + (req.headers['x-forwarded-host'] || '') + '|' + (req.headers['host'] || '');
21
+ return h.indexOf(DOMAIN) !== -1;
22
+ }
23
+ var s = http.createServer(function(req, res) {
24
+ if (ok(req)) { proxy.web(req, res); } else { res.writeHead(200, {'Content-Type':'text/plain'}); res.end('200 OK'); }
25
+ });
26
+ s.on('upgrade', function(req, socket, head) {
27
+ if (ok(req)) { proxy.ws(req, socket, head); } else { socket.destroy(); }
28
+ });
29
+ s.listen(7860, function() { console.log('[GW] 7860'); });
30
+ GWEOF
31
+
32
+ RUN cat > /gw/start.sh << 'SHEOF'
33
+ #!/bin/sh
34
+ cd /app && PORT=3001 node index.js &
35
+ sleep 2
36
+ cd /gw && exec node gateway.js
37
+ SHEOF
38
+
39
+ RUN chmod +x /gw/start.sh
40
+
41
+ RUN adduser -D -u 1000 user && \
42
+ chown -R user:user /app /gw
43
+
44
+ USER user
45
+ EXPOSE 7860
46
+ CMD ["/gw/start.sh"]