digidem / osm-p2p-server

Peer-to-peer OpenStreetMap API v0.6 Server for osm-p2p-db
BSD 2-Clause "Simplified" License
87 stars 10 forks source link

Experimental code re-organization - do not merge #11

Closed gmaclennan closed 8 years ago

gmaclennan commented 8 years ago

Here are some ideas for code re-organization. This branch was based on an earlier version of osm-p2p-server, so the handlers need updated.

The aims of this change are:

I'm not sure this re-organization achieves this aim, but putting this up here for discussion.

Each route has its own file/module under routes. It expects route parameters to be attached to req.params and query string parameters to be attached to req.query. Express and Hapi and other popular frameworks use this convention in their route handler. If the framework you want to use does not do this, you can write middleware to add those properties.

'Handlers' are the logic for operations on each route. If we wanted to, for example, modify iD Editor so that it does not interact with any server, we could replace the xhr code with handlers/bbox_query_stream. Handlers should not have any dependencies on server implementation, and just receive necessary params, an osm-p2p-db instance, and they should return a stream. Note that handlers/addChangeset does not currently do this - need to update that code.