Set up streams with parse-server
Prerequisites
Before getting started, make sure you have followed this section Run parse-server locally and have a server already set up locally.
Video Tutorial
Step 1: Set up webhook route
Inside .env
file you can add a new variable STREAMS_WEBHOOK_URL
.
STREAMS_WEBHOOK_URL = '/streams-webhook'
Inside index.ts
import streamSync
plugin.
// @ts-ignore
import ParseServer from 'parse-server';
import Moralis from 'moralis';
import config from './config';
import cors from 'cors';
import express from 'express';
import http from 'http';
import ngrok from 'ngrok';
import { parseDashboard } from './parseDashboard';
import { parseServer } from './parseServer';
//Import the plugin
import { streamsSync } from '@moralisweb3/parse-server';
Set up your express app to use streamSync
with your route and your API key.
//........
app.use(cors());
//Set up streamSync
app.use(
streamsSync(parseServer, {
apiKey: config.MORALIS_API_KEY,
webhookUrl: config.STREAMS_WEBHOOK_URL,
}),
);
app.use(`/server`, parseServer.app);
//.........
Set up ngrok.
const httpServer = http.createServer(app);
httpServer.listen(config.PORT, async () => {
if (config.USE_STREAMS) {
//Set up ngrok
const url = await ngrok.connect(config.PORT);
// eslint-disable-next-line no-console
console.log(
`Moralis Server is running on port ${config.PORT} and stream webhook url ${url}${config.STREAMS_WEBHOOK_URL}`,
);
} else {
// eslint-disable-next-line no-console
console.log(`Moralis Server is running on port ${config.PORT}.`);
}
});
You can now build the project and start it locally.
- npm
- Yarn
npm run build
yarn run build
Start the project.
- npm
- Yarn
npm run start
yarn run start
After staring your server you shoud see a similar message in your terminal. This will be the webwook url your would use to create a stream
Moralis Server is running on port 1337 and stream webhook url https://23ae-5-12-44-202.ngrok.io/streams-webhook
Step 2: Create a stream
To create a stream you can check the following docs Create a stream using Admin Panel or follow the Youtube Tutorial starting from minute 7:15.
You will have to provide your ngrok url that you got from the previous step.
Paste your ngrok url https://xxxx-xx-xx-xxxx.ngrok.io/streams-webhook