···11-# xcvr-backend
22-a backend service that allows the dynamic creation of lrc servers. see it live at [xcvr.chat](http://xcvr.chat/)
11+# rvcx
22+this is the backend for the xcvr appview. it uses lrcd to host the lrc servers,
33+postgres to cache the atproto data, atproto-oauth-golang as an oauth client,
44+and probably some other things i am forgetting!
3544-this is just the backend, for a frontend, consider using [xcvr](https://github.com/rachel-mp4/xcvr/)
66+## principles
77+the xcvr atproto ecosystem has backend appviews which are simultaneously
88+atproto actors who write signet records to their repos in order to have
99+bidirectional confidence that off-protocol communication occured
510611## how to run
77-```{bash}
88-$ cd server
99-$ go run ./cmd
1212+i don't really test this in development since i added oauth, this likely will
1313+change in the future
1414+1515+in production, you must create a .env file that contains the following
1616+environment variables, setting secrets as appropriate
1717+1818+```
1919+POSTGRES_USER=xcvr
2020+POSTGRES_PASSWORD=secret
2121+POSTGRES_DB=xcvrdb
2222+POSTGRES_PORT=15432
2323+MY_NAME=xcvr
2424+MY_IDENTITY=xcvr.org
2525+MY_SECRET=secret
2626+MY_METADATA_PATH=/meta/client-metadata.json
2727+MY_TOS_PATH=/meta/tos
2828+MY_POLICY_PATH=/meta/policy
2929+MY_LOGO_PATH=/public/xcvr.svg
3030+MY_OAUTH_CALLBACK=/oauth/callback
3131+MY_JWKS_PATH=/oauth/jwks.json
3232+SESSION_KEY=secret
3333+LRCD_SECRET=secret
1034```
11351212-## how to deploy
1313-1. install nginx
1414-2. copy xcvr.conf to /etc/nginx/conf.d/ (change the server_name directive to your domain name)
1515-3. copy static files to /var/www/xcvr/ (if using xcvr for your frontend, then copy the contents of the dist directory generated by `npm run build` to the /var/www/xcvr/)
1616-4. start nginx
1717-5. run xcvr-backend
3636+the first four of course have to do with your postgres instance, i think the
3737+postgres port is just 15432 because i was having conflicts on mac, i don't
3838+think what you set it to is very important. they are also used in the migration
3939+scripts. migratedown and migrateup require you to install golang migrate, and
4040+psql requires you to install psql. MY_NAME, MY_IDENTITY, MY_METADATA_PATH,
4141+MY_TOS_PATH, MY_POLICY_PATH, MY_LOGO_PATH, MY_OAUTH_CALLBACK and MY_JWKS_PATH
4242+are used for oauth, MY_IDENTITY is the hostname, but also the atproto handle of
4343+the backend's repo. the MY_SECRET is variable is thus the backend's app
4444+password. in order to be an oauth client, you need a jwks that you serve at
4545+MY_JWKS_PATH, but of course you need to generate this using haileyok's
4646+atproto-oauth-golang, and then save jwks.json in the top level rvcx directory
4747+as jwks.json. SESSION_KEY and LRCD_SECRET are two more keys that you need to
4848+generate in addition to POSTGRES_PASSWORD. SESSION_KEY encrypts the oauth
4949+session data, and LRCD_SECRET is used to generate nonces that prevent anyone
5050+from submitting other people's unauthenticated messages.
18511919-## endpoints
2020-GET http://localhost:8080/xrpc/getChannels - gets a list of all active channels
5252+once you have your .env file, you then need to run `sudo docker-compose up -d`
5353+and then `sudo ./migrateup` if it is your first time running the server. if you
5454+need to reset the database, you can do `sudo docker-compose down --volumes`, of
5555+course, be careful with this, rvcx does not currently have a way to backfill
5656+the database!!! these commands are run in the main rcvx directory.
21572222-POST http://localhost:8080/xrpc/initChannel - accepts json containing metadata about a channel and creates it
5858+then, you need to `cd server`, and then you can `go run ./cmd` to start the
5959+backend.
6060+6161+i also have included my nginx configuration. after installing nginx, you need
6262+to put that in the conf.d folder, if you're on ubuntu. i think that nginx
6363+differs a bit depending on your distro, you can probably figure it out, i might
6464+be able to help troubleshoot but it'd probably the blind leading the blind
6565+there haha
6666+6767+of course, this is just the backend, so alongside nginx, you should build the
6868+frontend and copy the files to the appropriate location. the frontend uses
6969+sveltekit and i just have it generate a static site bc i don't really care atp,
7070+setup is already contrived enough
23712424-## servers
2525-servers are served on ephemeral ports at ws://localhost:PORT/ws
7272+as with xcvr (frontend) i think this is under mit but i don't know enough
7373+apropos licensing at this moment in history to fully commit in that direction.
26742727-in production, their ports are exposed as ws://xcvr.chat/PORT/ws, which gets proxied to ws://127.0.0.1:PORT/ws7575+as for contributions, same thing i said in that other readme, i'd love help &
7676+you should let me know in advance so we don't make each other's lives hell :3
+8-8
server/cmd/main.go
···55 "errors"
66 "net/http"
77 "os"
88+ "rvcx/internal/atplistener"
99+ "rvcx/internal/atputils"
1010+ "rvcx/internal/db"
1111+ "rvcx/internal/handler"
1212+ "rvcx/internal/log"
1313+ "rvcx/internal/model"
1414+ "rvcx/internal/oauth"
815 "time"
99- "xcvr-backend/internal/atplistener"
1010- "xcvr-backend/internal/atputils"
1111- "xcvr-backend/internal/db"
1212- "xcvr-backend/internal/handler"
1313- "xcvr-backend/internal/log"
1414- "xcvr-backend/internal/model"
1515- "xcvr-backend/internal/oauth"
16161717 "github.com/joho/godotenv"
1818)
···22222323 gdeerr := godotenv.Load("../.env")
2424 if gdeerr != nil {
2525- logger.Println("i think you should make a .env file in the xcvr-backend directory !\n\nExample contents:\n-------------------------------------------------------------------\nPOSTGRES_USER=xcvr\nPOSTGRES_PASSWORD=secret\nPOSTGRES_DB=xcvrdb\nPOSTGRES_PORT=15432\n-------------------------------------------------------------------\n\nGood luck !\n\n")
2525+ logger.Println("i think you should make a .env file in the rvcx directory !\n\nExample contents:\n-------------------------------------------------------------------\nPOSTGRES_USER=xcvr\nPOSTGRES_PASSWORD=secret\nPOSTGRES_DB=xcvrdb\nPOSTGRES_PORT=15432\n-------------------------------------------------------------------\n\nGood luck !\n\n")
2626 panic(gdeerr)
2727 }
2828 store, err := db.Init()