Git Product home page Git Product logo

Comments (7)

dougmoscrop avatar dougmoscrop commented on July 17, 2024

It might be simpler to avoid modifying getFramework, and just extract this: https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/server.js#L38 in to your own app,

so you'd do something like (untested, sorry)

const EventEmitter = require('events').EventEmitter
const Serializer = require('xmlrpc/lib/serializer')
const Deserializer = require('xmlrpc/lib/deserializer')

const rpc = new EventEmitter()

rpc.on('foo', (error, params, callback) => {
})

module.exports.handler = serverlessHttp((request, response) => {
  const deserializer = new Deserializer()
  deserializer.deserializeMethodCall(request, function(error, methodName, params) {
    if (Object.prototype.hasOwnProperty.call(rpc._events, methodName)) {
       rpc.emit(methodName, null, params, function(error, value) {
          response.writeHead(200, {'Content-Type': 'text/xml'})
          response.end(error === null
            ? Serializer.serializeMethodResponse(value)
            : Serializer.serializeFault(error)
        })
    } else {
      response.writeHead(404)
      response.end()
    }
  })  
})

from serverless-http.

mjgs avatar mjgs commented on July 17, 2024

@dougmoscrop Thanks for the reply and code snippet idea. I really appreciate it.

So if I’m understanding correctly serverless-http just requires a handler function, and your idea is to basically extract that from the xmlrpc library, but additionally to create a separate independent event emitter. And then instead of adding the handlers for each method I want to call via xmlrpc protocol onto the xmlrpc object, I just use the separate event emitter.

Am I understanding correctly?

from serverless-http.

dougmoscrop avatar dougmoscrop commented on July 17, 2024

yep!

from serverless-http.

dougmoscrop avatar dougmoscrop commented on July 17, 2024

also the event emitter 'style' is just one way of doing it.. you could come up with your own dispatch scheme (such as just having a plain object/hash to lookup methodName), if you prefer, and just rely on xmlrpc for the serialize/deserialize.

from serverless-http.

mjgs avatar mjgs commented on July 17, 2024

Great advice thank you.

Do I end up loosing anything by extracting just the handle method? I’m thinking specifically about https, but maybe there’s something else. Btw it will be running in Netlify so https is configured by default.

How will that work in this setup, is it just as simple as using https in the url that I give to the client?

from serverless-http.

dougmoscrop avatar dougmoscrop commented on July 17, 2024

Right, in serverless functions, especially AWS Lambda-based ones, nothing is technically "listening", so the whole idea of HTTPS is externalized to your process and your code (your handler) is literally just a function that gets called by the runtime no different than any other function. This library is kind of like an abstraction that undoes another abstraction, if that makes sense.

I originally wrote it because we were fairly early adopters of AWS Lambda and wanted to be able to eject in to a Docker container/server with little to no changes (my attempt at Hexagonal architecture)

p.s. not sure if you've seen https://getampt.com but I will shamelessly plug it here :)

from serverless-http.

mjgs avatar mjgs commented on July 17, 2024

Thanks for the background info. I think I’m starting to understand how the pieces are situated now.

The ‘ejection’ capability was one of the reasons I started using serverless-http initially. It’s really cool to be able to run normal express apps locally but then just seamlessly get them running in the cloud.

Thanks for the hexagonal architecture link, looks interesting, will definitely look more into that later. The last few projects I’ve built have been very influenced by domain driven design, especially when it comes to using layers, adapters and reusing code.

Getampt sounds really cool :)

from serverless-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.