serverless-offline
Version:
Emulate AWS λ and API Gateway locally when developing your Serverless project
69 lines (55 loc) • 1.59 kB
JavaScript
import crypto from "node:crypto"
import { formatToClfTime } from "../../../utils/index.js"
const { now } = Date
const connectedAt = new Map()
export default class WebSocketRequestContext {
constructor(eventType, route, connectionId) {
this.
this.
this.
if (eventType === "CONNECT") {
connectedAt.set(connectionId, now())
}
this.
if (eventType === "DISCONNECT") {
connectedAt.delete(connectionId)
}
}
create() {
const timeEpoch = now()
const requestContext = {
apiId: "private",
connectedAt: this.
connectionId: this.
domainName: "localhost",
eventType: this.
extendedRequestId: crypto.randomUUID(),
identity: {
accessKey: null,
accountId: null,
caller: null,
cognitoAuthenticationProvider: null,
cognitoAuthenticationType: null,
cognitoIdentityId: null,
cognitoIdentityPoolId: null,
principalOrgId: null,
sourceIp: "127.0.0.1",
user: null,
userAgent: null,
userArn: null,
},
messageDirection: "IN",
messageId: crypto.randomUUID(),
requestId: crypto.randomUUID(),
requestTime: formatToClfTime(timeEpoch),
requestTimeEpoch: timeEpoch,
routeKey: this.
stage: "local",
}
return requestContext
}
}