diff --git a/functions/nehubaConfig.js b/functions/nehubaConfig.js new file mode 100644 index 0000000000000000000000000000000000000000..52f1f91a7239b329c348c6b50adef7c05f6b0181 --- /dev/null +++ b/functions/nehubaConfig.js @@ -0,0 +1,38 @@ +const fs = require('fs') + +exports.handler = (ev, ctx, cb) => { + const { + path, + httpMethod, + headers, + queryStringParameters, + body, + isBase64Encoded, + } = ev + + + const re = /nehubaConfig\/(.+)$/.exec(path) + if (!re) { + return cb(null, { + status: 401, + body: `config name is required` + }) + } + + const configName = re[1] + fs.readFile(`./json/${configName}.json`, 'utf-8', (err, data) => { + if (err) { + return cb(null, { + status: 404, + body: `config ${configName} does not exist, ${err.toString()}` + }) + } + return cb(null, { + status: 200, + body: data, + headers: { + 'Content-type': 'application/json' + } + }) + }) +} \ No newline at end of file diff --git a/functions/templates/templates.js b/functions/templates.js similarity index 96% rename from functions/templates/templates.js rename to functions/templates.js index fb7d8cd88effc9256346a9f0cd75caa889b13531..753ff3e534440f4ea64b942d1a602ddc6a08d657 100644 --- a/functions/templates/templates.js +++ b/functions/templates.js @@ -1,5 +1,4 @@ const fs = require('fs') -const path = require('path') exports.handler = (ev, ctx, cb) => { diff --git a/netlify.toml b/netlify.toml index dfcc620f66bb184bb60e2b2da08c3ef1c83d27d1..100526f9f4e90783cf6566f33c775b8117a61994 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,6 @@ [build] publish="dist/aot/" - command="cp -R src/res/ext functions/templates/json && npm run build-aot" + command="cp -R src/res/ext functions/json && npm run build-aot" functions="functions" environment={ BACKEND_URL=".netlify/functions/" } \ No newline at end of file