Sign inSign up

3dwardsharp/couch_ws

By 3dwardsharp

•Updated over 8 years ago

couch websocket proxy via socket-pouch

Image
0

1.1K

3dwardsharp/couch_ws repository overview

⁠run -it

docker run -t -i -p 5984:5984 -p 8888:8888 3dwardsharp/couch_ws

⁠Dockerfile

FROM couchdb:2.1.1

RUN apt-get update -y -qq && apt-get install -y --no-install-recommends apt-transport-https

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -

RUN apt-get install -y --no-install-recommends \
    nodejs \
  && rm -rf /var/lib/apt/lists/*

COPY couch_ws.ini /opt/couchdb/etc/local.d/couch_ws.ini

RUN mkdir /opt/couch_ws

COPY package.json /opt/couch_ws
COPY couch_ws.js /opt/couch_ws

RUN cd /opt/couch_ws && npm i

EXPOSE  8888

⁠couch_ws.ini

[os_daemons]
daemon_name = /usr/bin/node /opt/couch_ws/couch_ws.js

⁠couch_ws.js

const socketPouchServer = require('socket-pouch/server');
const httpProxy = require('http-proxy');
const express = require('express');
const app = express();

app.get('/_up', function(req, res) {
  res.send('ok');
});

const webProxy = httpProxy.createProxyServer({ target: 'http://localhost:8080' });
app.get('/*', function(req, res){
	webProxy.web(req, res);
});
app.post('/*', function(req, res){
	webProxy.web(req, res);
});

socketPouchServer.listen(8080, {
  remoteUrl: 'http://localhost:5984',
  socketOptions: {origins: [ 
    'http://localhost:8080', 
    'https://your.domain']}
});

const proxy = httpProxy.createProxyServer({ target: 'http://localhost:8080', ws: true });
const server = require('http').createServer(app);
server.on('upgrade', function (req, socket, head) {
  console.log("proxying upgrade request", req.url);
  proxy.ws(req, socket, head);
});

server.listen(8888);

⁠package.json

{
  "name": "couch_ws",
  "version": "1.0.0",
  "description": "couch websocket proxy via socket-pouch",
  "main": "couch_ws.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "3dwardsharp",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.4",
    "express": "^4.16.3",
    "http-proxy": "^1.16.2",
    "socket-pouch": "^2.0.0"
  }
}

Tag summary

Content type

Image

Digest

Size

206.2 MB

Last updated

over 8 years ago

docker pull 3dwardsharp/couch_ws