import * as cloud from "@pulumi/cloud" ; import * as express from "express" ; const name = "cloudexample" ; interface Message { title : string ; info : string ; } const topic = new cloud . Topic < Message > ( name ) ; topic . subscribe ( name , async ( message ) => { console . log ( "Subscription fired." ) ; console . log ( "Got: " + JSON . stringify ( message ) ) ; } ) ; type AsyncRequestHandler = ( req : express . Request , res : express . Response , next : express . NextFunction ) => Promise < void > ; const asyncMiddleware = ( fn ) => ( req , res , next ) => { Promise . resolve ( fn ( req , res , next ) ) . catch ( next ) ; } ; const server = new cloud . HttpServer ( name , ( ) => { const app = express ( ) ; const router = express . Router ( ) ; app . use ( "/api" , router ) ; router . get ( "*" , asyncMiddleware ( async ( req , res ) => { try { await topic . publish ( { title : "Http endpoint hit!" , info : req . originalUrl } ) ; res . json ( { success : true } ) ; } catch ( err ) { res . json ( { error : JSON . stringify ( err ) } ) ; } } ) ) ; return app ; } ) ; export let url = server . url ;