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v5.39.0.\n * Original file: /npm/cloudmine-servercode@1.2.1/bin/server.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Generated by CoffeeScript 1.12.7\n(function() {\n  'use strict';\n  var Hapi, MAX_PAYLOAD_BYTES, Server, badRequest, createReqPayload, isTruthy, join, localReply, ref;\n\n  Hapi = require('hapi');\n\n  badRequest = require('boom').badRequest;\n\n  join = require('path').join;\n\n  ref = require('./remote_payload'), isTruthy = ref.isTruthy, createReqPayload = ref.create;\n\n  localReply = require('./local_reply');\n\n  MAX_PAYLOAD_BYTES = 20000000;\n\n  Server = (function() {\n    function Server() {\n      this.server = new Hapi.Server();\n      this.server.connection({\n        host: '0.0.0.0',\n        port: process.env.PORT || 4545\n      });\n      this.server.on('request-error', function(req, err) {\n        return console.log('Internal Server Error:', err);\n      });\n    }\n\n    Server.prototype._names = function() {\n      return this.server.route({\n        method: 'GET',\n        path: '/names',\n        handler: (function(_this) {\n          return function(req, reply) {\n            if (!_this.snippetNames) {\n              return reply(badRequest('Server Has not been started!'));\n            }\n            return reply(_this.snippetNames);\n          };\n        })(this)\n      });\n    };\n\n\n    /*\n    The required path is relative to this module...\n     */\n\n    Server.prototype._configure = function(context, path) {\n      this.requiredFile = context.require(path);\n      this.snippetNames = Object.keys(this.requiredFile);\n      return this._setupRoutes();\n    };\n\n\n    /*\n    We need local testing to behave the same as when the code is deployed on the PaaS but\n    normally coderunner does a bunch of work as the middleman. We recreate a lot of that logic\n    here and flip the local switch via an environment variable.\n     */\n\n    Server.prototype._setupRoutes = function() {\n      this._names();\n      if (isTruthy(process.env['CLOUDMINE'])) {\n        return this._setupDeployedRoutes();\n      } else {\n        return this._setupLocalTestingRoutes();\n      }\n    };\n\n    Server.prototype._setupLocalTestingRoutes = function() {\n      var SNIPPET_TIMEOUT, i, j, len, len1, localTestingHandler, path, paths, results;\n      paths = ['/v1/app/{appid}/run/{name}', '/v1/app/{appid}/user/run/{name}', '/v1/app/{appid}/user/{userId}/run/{name}'];\n      localTestingHandler = (function(_this) {\n        return function(original_req, reply) {\n          var req, snippet;\n          snippet = _this.requiredFile[original_req.params.name];\n          if (!snippet) {\n            return reply(badRequest('Snippet Not Found!'));\n          }\n          req = createReqPayload(original_req);\n          return snippet(req, localReply(reply, isTruthy(original_req.query.unwrap_result)));\n        };\n      })(this);\n      SNIPPET_TIMEOUT = 30000;\n      for (i = 0, len = paths.length; i < len; i++) {\n        path = paths[i];\n        this._setupPutAndPostRoute(path, localTestingHandler, SNIPPET_TIMEOUT);\n      }\n      results = [];\n      for (j = 0, len1 = paths.length; j < len1; j++) {\n        path = paths[j];\n        results.push(this._setupGetRoute(path, localTestingHandler, SNIPPET_TIMEOUT));\n      }\n      return results;\n    };\n\n    Server.prototype._setupDeployedRoutes = function() {\n      var deployedHandler, path;\n      path = '/code/{name}';\n      deployedHandler = (function(_this) {\n        return function(req, reply) {\n          var snippet;\n          snippet = _this.requiredFile[req.params.name];\n          if (!snippet) {\n            return reply(badRequest('Snippet Not Found!'));\n          }\n          return snippet(req, reply);\n        };\n      })(this);\n      this._setupPutAndPostRoute(path, deployedHandler);\n      return this._setupGetRoute(path, deployedHandler);\n    };\n\n    Server.prototype._setupPutAndPostRoute = function(path, handler, timeout) {\n      return this.server.route({\n        method: ['PUT', 'POST'],\n        path: path,\n        config: {\n          payload: {\n            maxBytes: MAX_PAYLOAD_BYTES\n          },\n          timeout: {\n            server: timeout || null\n          }\n        },\n        handler: handler\n      });\n    };\n\n    Server.prototype._setupGetRoute = function(path, handler, timeout) {\n      return this.server.route({\n        method: ['GET', 'DELETE'],\n        path: path,\n        handler: handler,\n        config: {\n          timeout: {\n            server: timeout || null\n          }\n        }\n      });\n    };\n\n    Server.prototype.start = function(context, path, cb) {\n      if (!path) {\n        throw Error('No Path Given!');\n      }\n      this._configure(context, path);\n      return this.server.start(function(err) {\n        if (cb) {\n          return cb(err);\n        }\n      });\n    };\n\n    return Server;\n\n  })();\n\n  module.exports = new Server();\n\n}).call(this);\n"]}