Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler redesign #465

Open
metrue opened this issue Mar 1, 2020 · 0 comments
Open

Bundler redesign #465

metrue opened this issue Mar 1, 2020 · 0 comments
Labels
enhancement RFC idea, design, and tasks.

Comments

@metrue
Copy link
Owner

metrue commented Mar 1, 2020

The only thing fx does is to make a single function to be an HTTP service, fx takes two steps to finish the process,

  • Wraps the function into a web server project and make it be the handler function of the HTTP request.
  • Builds the bundled web server to be Docker image, then run it as a Docker container and expose the service port.

bundler is the component responsible for step 1: wrap a single function (and its dependencies) into a web server. Take a Node web service as an example, the project looks like this,

helloworld
├── Dockerfile
├── app.js
└── fx.js

And the codes is pretty simple,

app.js

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const cors = require('@koa/cors');
const fx = require('./fx');

const app = new Koa();
app.use(cors({
  origin: '*',
}));
app.use(bodyParser());
app.use(fx);

app.listen(3000);

fx.js

module.exports = (ctx) => {
  ctx.body = 'hello world'
}

Dockerfile

FROM metrue/fx-node-base

COPY . .
EXPOSE 3000
CMD ["node", "app.js"]

You can see that it's a web service built with Koa, the request handler function defined in fx.js to response plain text hello world, so to make a general JavaScript/Node function to be a web service, we only have to put it into fx.js above, then build and run it with Docker and that's it.

To support different programming languages, fx needs to implement different bundlers, the reasons are,

  • The way to set up a web service is different in different languages
  • The way to manage dependency is different in different languages.

So there will be (are) different bundlers in fx.

go-bundler: based on Gin
ruby-bundler: based on Sinatra
node-bundler: based on Koa
python-bundler: based on flask
...
@metrue metrue mentioned this issue Mar 8, 2020
4 tasks
@metrue metrue added the RFC idea, design, and tasks. label Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement RFC idea, design, and tasks.
Projects
None yet
Development

No branches or pull requests

1 participant