diff --git a/functions/templates.js b/functions/templates.js deleted file mode 100644 index cb683496e188016434ad94df57f42bd7db9be274..0000000000000000000000000000000000000000 --- a/functions/templates.js +++ /dev/null @@ -1,33 +0,0 @@ -exports.handler = (ev, ctx, cb) => { - - const { - path, - httpMethod, - headers, - queryStringParameters, - body, - isBase64Encoded, - } = ev - - const templates = [ - // 'infant', - 'bigbrain', - 'colin', - 'MNI152', - 'waxholmRatV2_0', - 'allenMouse' - ] - - const resp = { - templates, - ev - } - - cb(null, { - status: 400, - body: JSON.stringify(resp), - headers: { - 'Content-type': 'application/json' - } - }) -} \ No newline at end of file diff --git a/functions/templates/templates.js b/functions/templates/templates.js new file mode 100644 index 0000000000000000000000000000000000000000..fb7d8cd88effc9256346a9f0cd75caa889b13531 --- /dev/null +++ b/functions/templates/templates.js @@ -0,0 +1,54 @@ +const fs = require('fs') +const path = require('path') + +exports.handler = (ev, ctx, cb) => { + + const { + path, + httpMethod, + headers, + queryStringParameters, + body, + isBase64Encoded, + } = ev + + const templates = [ + // 'infant', + 'bigbrain', + 'colin', + 'MNI152', + 'waxholmRatV2_0', + 'allenMouse' + ] + + const resp = templates + + const re = /templates\/(.+)$/.exec(path) + + if (re) { + const templateName = re[1] + fs.readFile(`./json/${templateName}.json`, 'utf-8', (err, data) => { + if (err) { + return cb(null, { + status: 500, + body: err.toString() + }) + } + return cb(null, { + status: 200, + body: data, + headers: { + 'Content-type': 'application/json' + } + }) + }) + } else { + cb(null, { + status: 200, + body: JSON.stringify(resp), + headers: { + 'Content-type': 'application/json' + } + }) + } +} \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index e7d167a5b48a47f668beec968de73bdc29fd060f..dfcc620f66bb184bb60e2b2da08c3ef1c83d27d1 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,6 @@ [build] publish="dist/aot/" - command="npm run build-aot" + command="cp -R src/res/ext functions/templates/json && npm run build-aot" functions="functions" environment={ BACKEND_URL=".netlify/functions/" } \ No newline at end of file