Skip to content

Commit

Permalink
Update Moralis index for SSL compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
king112ola committed Sep 19, 2024
1 parent 9c43f96 commit e648c3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 64 deletions.
23 changes: 18 additions & 5 deletions Moralis-Server-Self-Host/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import config from './config';
import { parseServer } from './parseServer';
// @ts-ignore
import ParseServer from 'parse-server';
import http from 'http';
import https from 'https';
import fs from 'fs';
import ngrok from 'ngrok';
import { streamsSync } from '@moralisweb3/parse-server';

import * as dotenv from 'dotenv';
dotenv.config();

export const app = express();

Moralis.start({
Expand All @@ -29,8 +33,16 @@ app.use(

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

const httpServer = http.createServer(app);
httpServer.listen(config.PORT, async () => {
// Load SSL certificates
const privateKey = fs.readFileSync(process.env.QUIC_ONLINE_BACK_END_PRIVATE_KEY??'', 'utf8');
const certificate = fs.readFileSync(process.env.QUIC_ONLINE_BACK_END_CERT??'', 'utf8');
const ca = fs.readFileSync(process.env.QUIC_ONLINE_BACK_END_CHAIN_CERT??'', 'utf8');

const credentials = { key: privateKey, cert: certificate, ca: ca };

// Create HTTPS server
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(config.PORT, async () => {
if (config.USE_STREAMS) {
const url = await ngrok.connect(config.PORT);
// eslint-disable-next-line no-console
Expand All @@ -39,8 +51,9 @@ httpServer.listen(config.PORT, async () => {
);
} else {
// eslint-disable-next-line no-console
console.log(`Moralis Server is running on port ${config.PORT}.`);
console.log(`Moralis Server is running on port ${config.PORT} with HTTPS.`);
}
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
ParseServer.createLiveQueryServer(httpsServer);
59 changes: 0 additions & 59 deletions Moralis-Server-Self-Host/src/ssl_index.ts

This file was deleted.

0 comments on commit e648c3d

Please sign in to comment.