CTFNote icon indicating copy to clipboard operation
CTFNote copied to clipboard

WebSocket gives error 405 on CloudFlare

Open KristinnVikarJ opened this issue 2 years ago • 6 comments

I've been trying to setup CTFNote on my server, but everytime I try to open a pad for any task it simply opens an iframe of the index page. Only change I've done was change the port from 80 to 8080

KristinnVikarJ avatar Oct 09 '21 00:10 KristinnVikarJ

Hello,

I've been trying to setup CTFNote on my server

What branch/commit do you use ? How do you start CTFNote ?

Only change I've done was change the port from 80 to 8080

Please, send the output of git diff. Here is what it should look like :

diff --git a/docker-compose.yml b/docker-compose.yml
index ea6564c..0798655 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -32,7 +32,7 @@ services:
       - api
       - codimd
     ports:
-      - 80:80
+      - 8080:80
   codimd:
     image: quay.io/hedgedoc/hedgedoc:1.9.0-alpine
     environment:

XeR avatar Oct 11 '21 08:10 XeR

git diff is

diff --git a/docker-compose.yml b/docker-compose.yml
index f34e7d6..9571060 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -38,7 +38,7 @@ services:
     depends_on:
       - hedgedoc
     ports:
-      - 80:80
+      - 8080:8080
   hedgedoc:
     image: quay.io/hedgedoc/hedgedoc:1.9.0-alpine
     environment:
diff --git a/front/nginx.conf b/front/nginx.conf
index 8fa8e34..e411c65 100644
--- a/front/nginx.conf
+++ b/front/nginx.conf
@@ -1,6 +1,6 @@
 server {
-    listen 80;
-    listen [::]:80;
+    listen 8080;
+    listen [::]:8080;

     server_name    localhost;
     server_tokens  off;

But changing this in the newest commit causes the grahpql websocket to freak out I have cloudflare set up to handle the ssl stuff for me, the request seems to go through but the websocket instantly closes with an error saying "Unexpected server response: 405"

KristinnVikarJ avatar Oct 19 '21 23:10 KristinnVikarJ

I have cloudflare set up to handle the ssl stuff for me

I do not use CloudFlare, but I know that some team deployed CTFNote with it. I don't think this is the problem. Can you try without CloudFlare just in case ?

But changing this in the newest commit causes the grahpql websocket to freak out

Can you be more specific about what "to freak out" means ? Ideally, we'd like to see the output of your browser's console.

Can you try with tag v2.0.1 ?

Assuming you have no data yet :

docker-compose down -v # This destroys the database !

git checkout v2.0.1
docker-compose build --pull
docker-compose up -d

sleep 5

docker-compose top
docker-compose logs front api

This should print the following list of processes (or equivalent)

ctfnote-api-1
UID    PID      PPID     C    STIME   TTY   TIME       CMD
1000   208020   207993   3    22:07   ?     00:00:00   node /opt/yarn-v1.22.15/bin/yarn.js start   
1000   208374   208020   12   22:07   ?     00:00:00   /usr/local/bin/node dist/index.js           

ctfnote-db-1
UID   PID      PPID     C    STIME   TTY   TIME       CMD
999   208013   207966   0    22:07   ?     00:00:00   postgres                                                     
999   208219   208013   0    22:07   ?     00:00:00   postgres: checkpointer                                       
999   208220   208013   0    22:07   ?     00:00:00   postgres: background writer                                  
999   208221   208013   0    22:07   ?     00:00:00   postgres: walwriter                                          
999   208222   208013   0    22:07   ?     00:00:00   postgres: autovacuum launcher                                
999   208223   208013   0    22:07   ?     00:00:00   postgres: stats collector                                    
999   208224   208013   0    22:07   ?     00:00:00   postgres: logical replication launcher                       
999   208529   208013   0    22:07   ?     00:00:00   postgres: user_postgraphile ctfnote 172.27.0.3(47926) idle   
999   208530   208013   1    22:07   ?     00:00:00   postgres: user_postgraphile ctfnote 172.27.0.3(47928) idle   
999   208577   208013   0    22:07   ?     00:00:00   postgres: ctfnote hedgedoc 172.27.0.4(37468) idle            
999   208578   208013   0    22:07   ?     00:00:00   postgres: ctfnote hedgedoc 172.27.0.4(37470) idle            
999   208579   208013   0    22:07   ?     00:00:00   postgres: ctfnote hedgedoc 172.27.0.4(37472) idle            

ctfnote-front-1
UID    PID      PPID     C    STIME   TTY   TIME       CMD
root   208433   208413   0    22:07   ?     00:00:00   nginx: master process nginx -g daemon off;   
100    208544   208433   0    22:07   ?     00:00:00   nginx: worker process                        

ctfnote-hedgedoc-1
UID     PID      PPID     C    STIME   TTY   TIME       CMD
10000   208253   208234   14   22:07   ?     00:00:01   node app.js                                              
10000   208565   208253   1    22:07   ?     00:00:00   /usr/local/bin/node /hedgedoc/lib/workers/dmpWorker.js   

And the following logs

ctfnote-api-1  | [1/5] waiting 1 seconds...yarn run v1.22.15
ctfnote-api-1  | $ NODE_ENV=production node dist/index.js
ctfnote-api-1  | Listening on :3000

ctfnote-db-1   | The files belonging to this database system will be owned by user "postgres".
ctfnote-db-1   | This user must also own the server process.
ctfnote-db-1   | 
ctfnote-db-1   | The database cluster will be initialized with locale "en_US.utf8".
ctfnote-db-1   | The default database encoding has accordingly been set to "UTF8".
ctfnote-db-1   | The default text search configuration will be set to "english".
ctfnote-db-1   | 
ctfnote-db-1   | Data page checksums are disabled.
ctfnote-db-1   | 
ctfnote-db-1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
ctfnote-db-1   | creating subdirectories ... ok
ctfnote-db-1   | selecting dynamic shared memory implementation ... posix
ctfnote-db-1   | selecting default max_connections ... 100
ctfnote-db-1   | selecting default shared_buffers ... 128MB
ctfnote-db-1   | selecting default time zone ... Etc/UTC
ctfnote-db-1   | creating configuration files ... ok
ctfnote-db-1   | running bootstrap script ... ok
ctfnote-db-1   | performing post-bootstrap initialization ... ok
ctfnote-db-1   | syncing data to disk ... ok
ctfnote-db-1   | 
ctfnote-db-1   | 
ctfnote-db-1   | Success. You can now start the database server using:
ctfnote-db-1   | 
ctfnote-db-1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
ctfnote-db-1   | 
ctfnote-db-1   | initdb: warning: enabling "trust" authentication for local connections
ctfnote-db-1   | You can change this by editing pg_hba.conf or using the option -A, or
ctfnote-db-1   | --auth-local and --auth-host, the next time you run initdb.
ctfnote-db-1   | waiting for server to start....2021-10-21 20:10:13.643 UTC [48] LOG:  starting PostgreSQL 14.0 (Debian 14.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
ctfnote-db-1   | 2021-10-21 20:10:13.643 UTC [48] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
ctfnote-db-1   | 2021-10-21 20:10:13.645 UTC [49] LOG:  database system was shut down at 2021-10-21 20:10:13 UTC
ctfnote-db-1   | 2021-10-21 20:10:13.648 UTC [48] LOG:  database system is ready to accept connections
ctfnote-db-1   |  done
ctfnote-db-1   | server started
ctfnote-db-1   | CREATE DATABASE
ctfnote-db-1   | 
ctfnote-db-1   | 
ctfnote-db-1   | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh
ctfnote-db-1   | Multiple database creation requested: hedgedoc
ctfnote-db-1   |   Creating user and database 'hedgedoc'
ctfnote-db-1   | CREATE ROLE
ctfnote-db-1   | CREATE DATABASE
ctfnote-db-1   | GRANT
ctfnote-db-1   | Multiple databases created
ctfnote-db-1   | 
ctfnote-db-1   | 2021-10-21 20:10:13.875 UTC [48] LOG:  received fast shutdown request
ctfnote-db-1   | waiting for server to shut down....2021-10-21 20:10:13.875 UTC [48] LOG:  aborting any active transactions
ctfnote-db-1   | 2021-10-21 20:10:13.876 UTC [48] LOG:  background worker "logical replication launcher" (PID 55) exited with exit code 1
ctfnote-db-1   | 2021-10-21 20:10:13.877 UTC [50] LOG:  shutting down
ctfnote-db-1   | 2021-10-21 20:10:13.884 UTC [48] LOG:  database system is shut down
ctfnote-db-1   |  done
ctfnote-db-1   | server stopped
ctfnote-db-1   | 
ctfnote-db-1   | PostgreSQL init process complete; ready for start up.
ctfnote-db-1   | 
ctfnote-db-1   | 2021-10-21 20:10:13.999 UTC [1] LOG:  starting PostgreSQL 14.0 (Debian 14.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
ctfnote-db-1   | 2021-10-21 20:10:13.999 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
ctfnote-db-1   | 2021-10-21 20:10:13.999 UTC [1] LOG:  listening on IPv6 address "::", port 5432
ctfnote-db-1   | 2021-10-21 20:10:14.000 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
ctfnote-db-1   | 2021-10-21 20:10:14.003 UTC [68] LOG:  database system was shut down at 2021-10-21 20:10:13 UTC
ctfnote-db-1   | 2021-10-21 20:10:14.006 UTC [1] LOG:  database system is ready to accept connections

XeR avatar Oct 21 '21 20:10 XeR

After switching from cloudflare and using certbot it works completely fine It's weird because a project I'm working on that uses wss (where cloudflare handles the cert) has no issues with it

The websocket used to (on chrome) spam empty errors, but on microsoft edge it gave an actual error saying "Unexpected server response: 405"

But after completely restarting the installation after the recent updates its all working perfectly

Later I had some minor issues where I was unable to migrate properly because docker-compose exec refuses to give me any output so I had to tell everyone to re-register on the website but that's not too big of a deal.

KristinnVikarJ avatar Oct 21 '21 21:10 KristinnVikarJ

Hmmm… this is quite surprising ! 405 is "Method Not Allowed". I'll keep this issue opened and change its title in the hope of catching the attention of those who have the same problem so they can join the conversation. :-)

XeR avatar Oct 21 '21 21:10 XeR

Hi,

Have you tried this: image

https://docs.hedgedoc.org/guides/reverse-proxy/

presianbg avatar May 18 '22 17:05 presianbg