Comments (7)
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.
@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.
yep!
from serverless-http.
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.
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.
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.
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)
- When using ALB and Lambda with multi value headers, regular headers are not being added to the multiValueHeaders object HOT 6
- Receiving null from lambda HOT 5
- serverless-http examples for Loopback HOT 1
- Using this library with AWS function URLs? HOT 3
- body-parser middleware not triggering in Express 5/body-parser 2.x HOT 2
- Cannot work with graphql, express-graphql or graphql-http
- Multiple `set-cookie` don't end up in the final response when an ALB is the trigger
- Integration with websockets HOT 1
- gRPC connect-es support
- Double logging since v3.1.1 HOT 1
- Is there a way to disable or replacing logging? HOT 1
- How to properly wrap the http.createServer? HOT 4
- Streaming response HOT 5
- Use with Serverless Dashboard V2.0 and CLI V3 HOT 4
- {"message":"Missing Authentication Token"}
- Support Elysia.js
- Buffer in request.body
- Catch-all error handling with API GW?
- Is this repo still being maintained? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-http.