Hi all. I am running into a speed bump where I cant seem to get live queries working. I have downloaded the demo files and my index.ts for the server looks like this:
import Moralis from 'moralis';
import express from 'express';
import cors from 'cors';
import config from './config';
import {
// parseServer,
parseTestServer,
// parseIcoServer,
// parseServeDemoServer,
} from './parseServer';
// import { parseDashboard } from './parseDashboard';
// @ts-ignore
import ParseServer from 'parse-server';
import http from 'http';
export const app = express();
Moralis.start({
apiKey: config.MORALIS_API_KEY,
});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
// app.use(`/server`, parseServer);
app.use(`/server`, parseTestServer);
// app.use(`/server`, parseIcoServer);
// app.use(`/server`, parseServeDemoServer);
// app.use(`/dashboard`, parseDashboard);
const httpServer = http.createServer(app);
httpServer.listen(config.PORT, () => {
// eslint-disable-next-line no-console
console.log(`Moralis Test Server is running on port ${config.PORT}.`);
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
and i am trying to subscribe in my react-native app using this code:
const subscribeToMessages = async () => {
let query = new Moralis.Query("Messages");
query.equalTo("objectId", messagesPointer.id);
// console.log("messagesPointer.id", messagesPointer.id)
let subscription = await query.subscribe();
subscription.on("create", notifyOnMessage);
subscription.on("update", notifyOnMessage);
// subscription.on('create', result => notifyOnMessage(result));
return subscription;
};
const notifyOnMessage = (result) => {
// console.log("notifyOnMessage", result);
setUpdated(result);
// notifyOnType(result);
};
normal queries work, but live queries are not working. When i send a new chat message the new message isnt sent from the server to the app.
if i connect to the Moralis V1 server everything works fine. But if I connect to my self hosted server using the demo files, the live query doesnt seem to be working. Is anyone else having the same problem? if so how did you fix it? thanks in advance.
Iv managed to get most things working self hosted, but this is a major hurdle that i cant seem to figure out.