Websocket connection failed in Supabase local deployment - supabase

I'm trying to use Supabase's realtime updates locally, and I'm getting the following error
WebSocket connection to 'ws://localhost:54321/realtime/v1/websocket?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0&vsn=1.0.0' failed
The same code seems to be working on prod Supabase. What's going wrong here?
I'm using Supabase CLI v1.29.1, and #supabase/supabase-js v2.2.3.
The same code was working before I updated my whole stack, i.e. updated Supabase CLI as well as #supabase/supabase-js, and moved to Postgres v15 locally (i.e. in config.toml), from v14 previously.
Below is a sample of my TS code
supabase
.channel("public:table_name")
.on(
"postgres_changes",
{
event: "*",
schema: "public",
table: "public:table_name",
},
(payload) => console.log(payload)
)
.subscribe();
Edit: I tried to use https://realtime.supabase.com/inspector to connect to my local realtime instance but even that errored out with the same error. I'm suspecting the might be some issues in the local Supabase server.

This issue has been resolved in Supabase CLI v1.30.0: https://github.com/supabase/cli/releases/tag/v1.30.0

Related

How to setup ArangoDB replication via the ArangoDB Go driver

I need to set up a simple replication schema with a secondary database. I figured out that using arangosh I can set it up with the following commands:
db._useDatabase("myDB");
require("#arangodb/replication").setupReplication({
endpoint: "tcp://main-server:8529",
username: "user",
password: "pass",
verbose: false,
includeSystem: false,
incremental: true,
autoResync: false,
autoStart: true,
restrictType: "include",
restrictCollections: [ "Products" ]
});
This setup, however does not seem to persist. Connection going down, or server restarts make it disappear.
So, I would like to set up some monitoring and re-establishment of the replication in my Go program.
I searched both the ArangoDB website Manual pages, and Go driver documentation but I could not find anything that would allow me to run the above setup in Go using the driver.
Additionally, I didn't find how I could interface with arangosh, and possibly run the JS code above and get the results. Is that possible somehow using the Go driver?
I accidentally found a solution to this.
The Golang driver does not provide this functionality. But Arango has a pretty simple HTTP based API which allows access to all functions and features of the database engine.
Here's the link to the documentation I used: https://www.arangodb.com/docs/3.8/http/index.html
(I'm using version 3.8 because after that the type of replication I needed was no longer part of the community edition).
Setting up a replication requires just two steps:
PUT request to the /_db/yourDBname/_api/replication/applier-config with a JSON payload:
{
"endpoint":"tcp://serverIP:8529",
"database":"yourDBname",
"username":"root",
"password":"password",
"autoResync": true,
"autostart":true
}
And another PUT request to get the replication actually started, to /_db/yourDBname/_api/replication/applier-start . This one doesn't need any payload
And to see how things are going you can do a GET request to /_db/yourDBname/_api/replication/applier-state
All these requests need a JWT token that you can get with a POST request to /_open/auth with a payload of:
{
"username": "user",
"password": "passwd"
}
The token you receive will need to be included in the HTTP header as a bearer token. Pretty simple.

Nuxt serverInit axios on localhost getting ENOTFOUND

I'm making a website using NuxtJS for the front-end, and Laravel for the backend.
I need to have some data available on every page, so I fetch it using the nuxtServerInit function like so:
async nuxtServerInit({ commit }, { $axios }) {
const items= await $axios.$get('items')
commit('saveItems', items)
}
This works fine when pointing to my Laravel app that's already online, but not when I'm running it on my local machine. I get an "get addrinfo ENOTFOUND 3213" error.
My .env file contains the baseURL for axios, so local would be:
API_URL=http://127.0.0.1:8000/v1/
I tried many things but to no avail. It works when using the live backend, and there's no problem with the API_URL as it works on every other function/page apart from the nuxtServerInit one. I tried:
Using nuxt/dotenv as well as their new runtimeConfig settings to configure Axios' base URL in nuxt.config.js
Changing the port on which my backend runs
Changing the port on which my frontend runs
Adding a custom URl for my local backend (like devlocal.com pointing to localhost:8000)
But nothing works. My /etc/host file also correctly contains 127.0.0.1 as I saw it was a solution for a lot of ENOTFOUND errors on local.
I also tried changing the API_URL in my .env file to
API_URL=localhost:8000/v1/
But then I get "ENOTFOUND 8000" instead, or whichever the port I set my Laravel server to.
Please help!
Edit:
After toggling debug on Axios on dev, I found the host name is wrong in the request, which in turns make the URL incorrect:
reusedSocket: false,
host: '3213',
protocol: 'http:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'http://3213/http://localhost:8000/v1/items',
I don't know where the "3213" comes from. I tried setting default host/hostnames/port values to Axios in nuxt.config.js, but no luck.
Solved it randomly. I had a proxy variable setup in my environment variables (Win 10) called "http_proxy". Deleted it, and no more problem.

How to properly connect Nuxt.js with a laravel backend?

I am starting a new project, Nuxt.js for the frontend and Laravel for the backend.
How can I connect the two?
I have installed a new Nuxt project using create-nuxt-app, and a new laravel project.
As far as I have searched, I figured I need some kind of environment variables.
In my nuxt project, I have added the dotenv package and placed a new .env file in the root of the nuxt project.
And added CORS to my laravel project, as I have been getting an error.
The variables inside are indeed accessible from the project, and im using them
like this:
APP_NAME=TestProjectName
API_URL=http://127.0.0.1:8000
And accessing it like this:
process.env.APP_NAME etc'
To make HTTP calls, I am using the official Axios module of nuxt.js, and to test it i used it in one of the components that came by default.
The backend:
Route::get('/', function () {
return "Hello from Laravel API";
});
and from inside the component:
console.log(process.env.API_URL)//Gives 127.0.0.1:8000
//But this gives undefined
this.$axios.$get(process.env.API_URL).then((response) => {
console.log(response);
});
}
What am I doing wrong here?
I have tried to describe my setup and problem as best as I can. If I overlooked something, please tell me and I will update my question. Thanks.
Taking for granted that visiting https://127.0.0.1:8000/ in your browser you get the expected response, lets see what might be wrong in the front end:
First you should make sure that axios module is initialized correctly. Your nuxt.config.js file should include the following
//inclusion of module
modules: [
'#nuxtjs/axios',
<other modules>,
],
//configuration of module
axios: {
baseURL: process.env.API_URL,
},
Keep in mind that depending on the component's lifecycle, your axios request may be occurring in the client side (after server side rendering), where the address 127.0.0.1 might be invalid. I would suggest that you avoid using 127.0.0.1 or localhost when defining api_uris, and prefer using your local network ip for local testing.
After configuring the axios module as above, you can make requests in your components using just relative api uris:
this.$axios.$get('/').then(response => {
console.log(response)
}).catch(err => {
console.error(err)
})
While testing if this works it is very helpful to open your browser's dev tools > network tab and check the state of the request. If you still don't get the response, the odds are that you'll have more info either from the catch section, or the request status from the dev tools.
Keep us updated!
Nuxt has a routing file stucture to make it easy to set up server side rendering but also to help with maintainability too. This can cause Laravel and Nuxt to fight over the routing, you will need to configure this to get it working correctly.
I'd suggest you use Laravel-Nuxt as a lot of these small problems are solved for you.
https://github.com/cretueusebiu/laravel-nuxt

Trying to set up CAS with my Laravel project

I am using subfission/cas for my application. I have followed all installation steps. I am using windows, if that matters. More precisely, I have configured the following:
I ran the following in my terminal
composer require "subfission/cas" "dev-master"
I configured my Kernel.php accordingly, adding the following:
'cas.auth' => 'Subfission\Cas\Middleware\CASAuth',
'cas.guest' => 'Subfission\Cas\Middleware\RedirectCASAuthenticated',
I ran the following command:
php artisan vendor:publish
I also set up my cas server in my cas.php config file:
'cas_hostname' => env('CAS_HOSTNAME', 'cas.myserver.me'),
'cas_real_hosts' => env('CAS_REAL_HOSTS', 'cas.myserver.me'),
What I want is a middleware for all my routes, so I added the following route rule in my routes:
Route::middleware(['cas.auth'])->group(function ()
{
Route::get('/', function ()
{
return view('welcome');
});
});
Basically, I want to redirect everyone who is not logged in to the login page whenever I access the main page (for now, I will add more routes in the future). What happens is that the users are redirected to the login page when they are not logged in, but after the login I receive the following error:
ErrorException (E_WARNING)
DOMDocument::loadXML(): Opening and ending tag mismatch: hr line 1 and body in Entity, line: 1
No matter what view I'm redirecting the user to. I tried the default welcome page as well as an empty view, but I still get the same error.
EDIT: I have used the dev-master branch from subfission/cas for the above error and after switching to 2.1.1, I get a different error:
session_name(): Cannot change session name when headers already sent
EDIT 2: I did some more digging and I enabled internal errors in my cas client class with:
libxml_use_internal_errors(true);
And now I get the following:
Authentication failure: SA not validated Reason: bad response from the CAS server
And the cas response is:
The thing is that I use the same cas server for another 2 projects and it works well for those (but those aren't laravel projects.
I know it's been a while, but for anyone else having issues like this, the issue is the protocol selected for which your web service communicates with your CAS(Central Authentication Service) provider. There are two main protocols used for SSO/CAS in this package:
SAML(Security Assertion Markup Language) version 1.1 & 2
CAS Protocol v3.0
[Confusingly enough, CAS protocol shares the same namespace as the service.]
The idea is to match the protocol and version with your identity provider. It sounds like your provider is using CASv3.0, which is why disabling SAML worked.
Also, if you enable debug mode, you will see further error details in your log file to help your troubleshoot.
Best of luck!
I managed to solve the issue by disabling the SAML in the cas configure file:
'cas_enable_saml' => env('CAS_ENABLE_SAML', true),
change to
'cas_enable_saml' => env('CAS_ENABLE_SAML', false),

DateToArray is not defined in couchbase sync gateway

I write the code for couchbase view. follow this https://blog.couchbase.com/understanding-grouplevel-view-queries-compound-keys/
const mapDate = `function(doc, meta) {
emit(dateToArray(doc.updatedAt), {
_id: meta.id,
_rev: meta.rev,
updatedAt: doc.updatedAt
});
}`
and when I call http://localhost:4984/{db}/_design/{ddoc}/_view/{view} I got an error
Error running map function: ReferenceError: dateToArray is not defined
error image
I use sync-gateway version 1.4
What should I do?
In order to be able to query views via the Sync Gateway, you should be creating it through the Sync Gateway REST interface. You cannot query for views directly created on Couchbase Server.
This link should provide more insights into creating and querying views via Sync Gateway
The blog post you're referring to is about Couchbase Server, not Sync Gateway. So, it looks like dateToArray is not a pre-defined function available on Sync Gateway.

Resources