[Solved] Webhook and Stream API is not working with a self hosted server

Iā€™m trying to use Moralis Stream API and downloaded ā€œparse-server-migrationā€ from your github,

server is running well but the problem is a webhook url doesnā€™t work.
in moralis stream admin console, this message keeps showing.

Something went wrong!

Could not POST to https://------/streams. Please check your webhook URL.

at the same time, this error message appears on the running server,

error while inserting logs Cannot read properties of undefined (reading ā€˜appIdā€™)

I tried again with the new webhook url created by ngrok plugin.
There was no error in the create stream process. but I sent the coin to the registered address from my wallet, but the transaction data was not registered in the connected mongoDB.

I run the parse server in local and cloud environment both and failed.

here is my code of ā€˜index.tsā€™

import Moralis from 'moralis';
import express from 'express';
import cors from 'cors';
import { parseDashboard } from './parseDashboard';
import { parseServer } from './parseServer';
import { errorHandler } from './middlewares/errorHandler';
import config from './config';
import { apiRouter } from './apiRouter';
import { streamsSync } from '@moralisweb3/parse-server';
// @ts-ignore
import ParseServer from 'parse-server';
import http from "http";

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(
    streamsSync(parseServer, {
        apiKey: config.MORALIS_API_KEY,
        webhookUrl: config.STREAMS_WEBHOOK_URL,
    }),
);
app.use(`/${config.SERVER_ENDPOINT}`, parseServer);
app.use('/dashboard', parseDashboard);
app.use('/api', apiRouter);

app.use(errorHandler);

app.use(express.static('public'));

const httpServer = http.createServer(app);
app.listen(config.PORT, () => {
  // eslint-disable-next-line no-console
  console.log(`${config.APP_NAME} is running on port ${config.PORT}`);
});

ParseServer.createLiveQueryServer(httpServer);

parseDashboard.ts

// @ts-ignore
import ParseDashboard from 'parse-dashboard';
import config from './config';

export const parseDashboard = new ParseDashboard(
  {
    apps: [
      {
        appId: config.APPLICATION_ID,
        masterKey: config.MASTER_KEY,
        serverURL: config.SERVER_URL,
        appName: config.APP_NAME,
      },
    ],
    trustProxy: 1,
  },
{
    allowInsecureHTTP: config.ALLOW_INSECURE_HTTP,
}
);

It seems to be an issue somewhere there it tries to get the appId. Everything works fine with that self hosted server?

Looks like you are using an old version of the code, please check the latest version here https://docs.moralis.io/docs/run-parse-server-locally

to fix this error

in src/parserServer.ts change

import { ParseServer } from 'parse-server';

to

import ParseServer from 'parse-server';

and in index.ts change

app.use(`/server`, parseServer); 

to

app.use(`/server`, parseServer.app);
2 Likes

thank you! I solved my problem with your solution.
there was an another my mistake, I set the wrong my mongoDB url.
I missed the collection name of db.

DATABASE_URI = mongodb+srv://[ID]:[PASSWORD]@----.-------.mongodb.net/[ here ]?retryWrites=true&w=majority

2 Likes