-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
198 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
const { createServer, proxy } = require('aws-serverless-express'); | ||
const { init } = require('./dist/App'); | ||
const { Environment } = require('./dist/helpers/Environment'); | ||
const { Pool } = require('./dist/apiBase/pool'); | ||
const AWS = require('aws-sdk'); | ||
const { Logger } = require('./dist/helpers/Logger'); | ||
const { Repositories } = require('./dist/repositories/Repositories'); | ||
const { SocketHelper } = require('./dist/helpers/SocketHelper'); | ||
const { ApiGatewayManagementApi } = require('aws-sdk'); | ||
|
||
const gwManagement = new ApiGatewayManagementApi({ apiVersion: '2020-04-16', endpoint: process.env.SOCKET_URL }); | ||
|
||
Environment.init(process.env.APP_ENV); | ||
Pool.initPool(); | ||
|
||
const gwManagement = new ApiGatewayManagementApi({ apiVersion: '2020-04-16', endpoint: Environment.socketUrl }); | ||
|
||
|
||
async function logMessage(message) { | ||
const wl = new Logger(); | ||
wl.error(message); | ||
await wl.flush(); | ||
const wl = new Logger(); | ||
wl.error(message); | ||
await wl.flush(); | ||
} | ||
|
||
module.exports.handleWeb = function handleWeb(event, context) { | ||
AWS.config.update({ region: 'us-east-2' }); | ||
init().then(app => { | ||
const server = createServer(app); | ||
return proxy(server, event, context); | ||
}); | ||
AWS.config.update({ region: 'us-east-2' }); | ||
init().then(app => { | ||
const server = createServer(app); | ||
return proxy(server, event, context); | ||
}); | ||
|
||
} | ||
|
||
module.exports.handleSocket = async function handleSocket(event) { | ||
const rc = event.requestContext; | ||
const eventType = rc.eventType; | ||
const connectionId = rc.connectionId; | ||
//console.log(eventType); | ||
if (eventType == "DISCONNECT") await SocketHelper.handleDisconnect(connectionId) //; Repositories.getCurrent().connection.deleteForSocket(connectionId); | ||
else if (eventType == "MESSAGE") { | ||
const payload = { churchId: "", conversationId: "", action: "socketId", data: rc.connectionId } | ||
//try { | ||
await gwManagement.postToConnection({ ConnectionId: rc.connectionId, Data: JSON.stringify(payload) }).promise(); | ||
//} catch (e) { logMessage(e.toString()); } | ||
|
||
|
||
} | ||
return { statusCode: 200, body: 'success' } | ||
const rc = event.requestContext; | ||
const eventType = rc.eventType; | ||
const connectionId = rc.connectionId; | ||
//console.log(eventType); | ||
if (eventType == "DISCONNECT") await SocketHelper.handleDisconnect(connectionId) //; Repositories.getCurrent().connection.deleteForSocket(connectionId); | ||
else if (eventType == "MESSAGE") { | ||
const payload = { churchId: "", conversationId: "", action: "socketId", data: rc.connectionId } | ||
//try { | ||
await gwManagement.postToConnection({ ConnectionId: rc.connectionId, Data: JSON.stringify(payload) }).promise(); | ||
//} catch (e) { logMessage(e.toString()); } | ||
|
||
|
||
} | ||
return { statusCode: 200, body: 'success' } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"appEnv": "dev", | ||
"appName": "MessagingApi", | ||
"contentRoot": "http://localhost:3402", | ||
"fileStore": "disk", | ||
"mailSystem": "SMTP", | ||
"s3Bucket": "", | ||
"deliveryProvider": "local", | ||
"socketPort": 8087, | ||
"socketUrl": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"appEnv": "prod", | ||
"appName": "MessagingApi", | ||
"contentRoot": "https://content.churchapps.org", | ||
"fileStore": "S3", | ||
"mailSystem": "SES", | ||
"s3Bucket": "churchapps-content", | ||
"deliveryProvider": "aws", | ||
"socketPort": 0, | ||
"socketUrl": "wss://socket.churchapps.org/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"appEnv": "staging", | ||
"appName": "MessagingApi", | ||
"contentRoot": "https://content.staging.churchapps.org", | ||
"fileStore": "S3", | ||
"mailSystem": "SES", | ||
"s3Bucket": "staging-churchapps-content", | ||
"deliveryProvider": "aws", | ||
"socketPort": 0, | ||
"socketUrl": "wss://socket.staging.churchapps.org/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule apiBase
updated
from 05af8c to 7a7316
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
import { EnvironmentBase } from "../apiBase"; | ||
|
||
export class Environment extends EnvironmentBase { | ||
|
||
static deliveryProvider: string; | ||
static socketPort: number; | ||
static socketUrl: string; | ||
|
||
static init(environment: string) { | ||
let file = "dev.json"; | ||
if (environment === "staging") file = "staging.json"; | ||
if (environment === "prod") file = "prod.json"; | ||
|
||
|
||
const relativePath = "../../config/" + file; | ||
const physicalPath = path.resolve(__dirname, relativePath); | ||
|
||
const json = fs.readFileSync(physicalPath, "utf8"); | ||
const data = JSON.parse(json); | ||
this.populateBase(data); | ||
|
||
this.deliveryProvider = data.deliveryProvider; | ||
this.socketPort = data.socketPort; | ||
this.socketUrl = data.socketUrl; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Permissions' | ||
export * from '../apiBase/helpers/Interfaces' | ||
|
||
export { UniqueIdHelper } from "../apiBase/helpers"; | ||
export { UniqueIdHelper } from "../apiBase/helpers"; | ||
export { Environment } from "./Environment"; |
Oops, something went wrong.