module GCF::DeployTemplate

Defined in:

gcf/deploy_template.cr

Constant Summary

CRYSTAL_JS = "const fs = require('fs');\nconst child_process = require('child_process');\n\nfunction cmd(command) {\n console.log('$ '+command);\n var ret = child_process.execSync(command).toString();\n if(ret.length > 0) console.log(ret);\n return ret;\n}\n\nexports.init = function(req, res) {\n var proc = child_process.spawn('./crystal_function');\n var exception_lines = [];\n var params = JSON.stringify(req.body);\n fs.writeFileSync('/tmp/.gcf_params', params);\n\n proc.stdout.on('data', function(data) {\n var lines = data.toString().trim().split('\\n');\n lines.forEach(function(line) {\n if(line.startsWith(\"gcf-info: \")) {\n console.log(line.substring(10));\n } else if(line.startsWith(\"gcf-warn: \")) {\n console.warn(line.substring(10));\n } else if(line.startsWith(\"gcf-error: \")) {\n console.error(line.substring(11));\n } else if(line.startsWith(\"gcf-exception: \")) {\n console.log('exception line:', line);\n exception_lines.push(line.substring(15));\n } else {\n throw 'invalid console type: ' + line\n }\n });\n });\n\n proc.on('exit', function (code) {\n if(code) console.log('[gcf] crystal function exited with code ' + code.toString());\n if(!fs.existsSync('/tmp/.gcf_status')) throw 'missing status code';\n var status = parseInt(fs.readFileSync('/tmp/.gcf_status').toString().trim());\n if(status.toString() == \"NaN\") {\n //console.error(exception_lines.join(\"\\n\"));\n console.error(\"[gcf] an error occurred in your crystal function, but unfortunately we are not yet able to display the exception.\")\n res.status(500).send();\n } else if(fs.existsSync('/tmp/.gcf_text_output')) {\n var output = fs.readFileSync('/tmp/.gcf_text_output').toString();\n console.log('[gcf] sending text output with status', status);\n res.status(status).send(output);\n } else if(fs.existsSync('/tmp/.gcf_file_output')) {\n var path = fs.readFileSync('/tmp/.gcf_file_output').toString().trim();\n console.log('[gcf] sending file data from ', path);\n res.status(status).sendFile(path, { root: __dirname });\n } else if(fs.existsSync('/tmp/.gcf_redirect_url')) {\n var url = fs.readFileSync('/tmp/.gcf_redirect_url').toString().trim();\n console.log('[gcf] sending ' + status + ' redirect to ' + url);\n res.redirect(status, url);\n } else {\n throw 'invalid state -- no text output, file output, redirect, or exception specified';\n }\n });\n}"
PACKAGE_INFO = "{\n \"name\": \"deploy-template\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"crystal.js\",\n \"scripts\": {},\n \"author\": \"\"\n}"