make it easier to use this module with other routers / web frameworks such as Express
separate out the logic that handles operations from the server code, so that, for example, the route handlers could be directly imported and used in a JS OSM client without a server
make the code easier to read and maintain.
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.
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:
routes
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 toreq.params
and query string parameters to be attached toreq.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, anosm-p2p-db
instance, and they should return a stream. Note thathandlers/addChangeset
does not currently do this - need to update that code.