Giter Site home page Giter Site logo

Express 3.x about bones HOT 6 OPEN

makara avatar makara commented on August 16, 2024
Express 3.x

from bones.

Comments (6)

kkaefer avatar kkaefer commented on August 16, 2024

This is pretty tricky because express/connect changed the way servers are constructed. In Express 2.x, the app object inherited directly from HTTPserver, but in Express 3.x, this is just a wrapper and Express has its own application object.

In Bones, servers are "Classes" (in lack of a better term) that can be instantiated and then attached to another server or started as the root server. This means that on every instantiation, we'd have to create a server with express(), but in this case, the Bones Server object doesn't have all the .use(), .get() etc. functions, so this would break backwards-compatibility.

Another idea is to base Bones Server objects on express' application prototype and on instantiation, create a new express() server and swap out the __proto__ underneath it with the current object's prototype, and return that newly created object. This seems to be super hackish though and I'm not sure we should go down that route.

from bones.

kkaefer avatar kkaefer commented on August 16, 2024

/cc @Vertice

from bones.

kkaefer avatar kkaefer commented on August 16, 2024

The third option of course is to break backwards compatibility and move to a system that doesn't warp express servers into another Bones layer. The user would create an express server as normal and return that from the ServerName.bones.js file. The calling party could then either start the server or piggy-back it onto another server with .use(). Of course this means that it's nigh impossible to instantiate the same server twice. This could be restored by keeping the wrapping functionality and changing all calls in the initialize function from this.get() to this.app.get() etc.

from bones.

AdrianRossouw avatar AdrianRossouw commented on August 16, 2024

I'm not completely up to date on what is happening in express 3 (other than the templating changes), but why not just have the base server class instantiate the application, and then assign all the methods you want to redirect to the application.

// in a loop, obviously.
this.get = _.bind(this.app.get, this.app);

it's not like backbone and underscore dont do this kind of thing either, so i'm pretty sure it's kosher.

from bones.

makara avatar makara commented on August 16, 2024

Hi,

express-resource seems have a similar approach with @Vertice suggested, except it's not a redirect but a wrap.

/**
 * Setup http verb methods.
 */

methods.concat(['del', 'all']).forEach(function(method){
  Resource.prototype[method] = function(path, fn){
    if ('function' == typeof path
      || 'object' == typeof path) fn = path, path = '';
    this.map(method, path, fn);
    return this;
  }
});

I think we could do the same.

from bones.

LeoIannacone avatar LeoIannacone commented on August 16, 2024

Please update to Express 4.x.

from bones.

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.