serve-handler.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // serve-handler.js
  2. // This file defines a helper function for parsing an incoming URL into
  3. // the Public Path, Application, Instance and Private Path components.
  4. var serve = require( './serve' ),
  5. helpers = require( './helpers' ),
  6. url = require( 'url' ),
  7. libpath = require( 'path' );
  8. function File( request, response, filename ) {
  9. if ( ( helpers.IsFile( filename ) ) && ( request.method == "GET" ) ) {
  10. serve.File( request, filename.replace( /\//g, libpath.sep ), response, url.parse( request.url, true ) );
  11. return true;
  12. }
  13. return false;
  14. }
  15. function Component( request, response, filename ) {
  16. if ( request.method == "GET" ) {
  17. if ( helpers.IsFile( filename + ".yaml" ) ) {
  18. serve.YAML( filename.replace( /\//g, libpath.sep ) + ".yaml", response, url.parse( request.url, true ) );
  19. return true;
  20. }
  21. if ( helpers.IsFile ( filename + ".json" ) ) {
  22. serve.JSONFile( filename.replace( /\//g, libpath.sep ) + ".json", response, url.parse( request.url, true ) );
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. exports.File = File;
  29. exports.Component = Component;