Skip to content

Commit aa0854f

Browse files
committed
Enable loading of countries in netlify functions.
1 parent 8f3bb9f commit aa0854f

File tree

18 files changed

+38
-231
lines changed

18 files changed

+38
-231
lines changed

frontend/mock-api/autocomplete/countries.json

Lines changed: 0 additions & 212 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.js

frontend/mock-api/functions/api.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as serverless from "serverless-http";
2+
import * as createApi from "../../index";
3+
import * as express from "express";
4+
const app = createApi();
5+
const wrapper = express();
6+
7+
module.exports.handler = serverless(
8+
wrapper.use("/.netlify/functions/api", app)
9+
);

frontend/mock-api/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const path = require("path");
22
const version = require("../package.json").version;
3-
const EXPORT_FORM_CONFIG = require("./forms/export-form.json");
3+
const EXPORT_FORM_CONFIG = require("./functions/api/forms/export-form.json");
44
const mockAuthMiddleware = require("./mockAuthMiddleware");
55
const express = require("express");
66
const bodyParser = require("body-parser");
77
const cors = require("cors");
8-
98
// Taken from:
109
// http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
1110
function shuffleArray(array) {
@@ -113,7 +112,9 @@ function mountApi(app) {
113112
req,
114113
res
115114
) {
116-
res.sendFile(path.join(__dirname, `./results/${req.params.filename}`));
115+
res.sendFile(
116+
path.join(__dirname, "functions/api", `./results/${req.params.filename}`)
117+
);
117118
});
118119

119120
/*
@@ -123,14 +124,20 @@ function mountApi(app) {
123124
req,
124125
res
125126
) {
126-
res.sendFile(path.join(__dirname, "./concepts.json"));
127+
res.sendFile(path.join(__dirname, "functions/api", "./concepts.json"));
127128
});
128129

129130
app.get(
130131
"/api/datasets/:datasetId/concepts/:id",
131132
mockAuthMiddleware,
132133
function response(req, res) {
133-
res.sendFile(path.join(__dirname, `./concepts/${req.params.id}.json`));
134+
res.sendFile(
135+
path.join(
136+
__dirname,
137+
"functions/api",
138+
`./concepts/${req.params.id}.json`
139+
)
140+
);
134141
}
135142
);
136143

@@ -185,7 +192,9 @@ function mountApi(app) {
185192
mockAuthMiddleware,
186193
function response(req, res) {
187194
setTimeout(() => {
188-
res.sendFile(path.join(__dirname, "./stored-queries/25.json"));
195+
res.sendFile(
196+
path.join(__dirname, "functions/api", "./stored-queries/25.json")
197+
);
189198
}, LONG_DELAY);
190199
}
191200
);
@@ -250,7 +259,7 @@ function mountApi(app) {
250259
const countriesRequested = req.params.filterId === "production_country";
251260

252261
const storedValues = countriesRequested
253-
? require("./autocomplete/countries")
262+
? require("./functions/api/autocomplete/countries")
254263
: [
255264
"1008508208",
256265
"1015841172",
@@ -320,7 +329,7 @@ function mountApi(app) {
320329

321330
if (req.params.filterId !== "production_country") return null;
322331

323-
const countries = require("./autocomplete/countries");
332+
const countries = require("./functions/api/autocomplete/countries");
324333
const unknownCodes = values.filter(val => !countries.includes(val));
325334
const resolvedValues = values.filter(val => countries.includes(val));
326335

@@ -459,7 +468,9 @@ function mountApi(app) {
459468
mockAuthMiddleware,
460469
function response(req, res) {
461470
setTimeout(() => {
462-
res.sendFile(path.join(__dirname, "./form-configs/testconf.json"));
471+
res.sendFile(
472+
path.join(__dirname, "functions/api", "./form-configs/testconf.json")
473+
);
463474
}, LONG_DELAY);
464475
}
465476
);

frontend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start": "react-app-rewired start",
1313
"build-frontend": "react-app-rewired build",
1414
"build": "yarn build-frontend && yarn build-mock-backend",
15-
"build-mock-backend": "tsc mock-api/functions/*",
15+
"build-mock-backend": "tsc mock-api/functions/*/**.ts",
1616
"test": "react-app-rewired test",
1717
"eject": "react-scripts eject",
1818
"heroku-postbuild": "yarn run build",
@@ -75,6 +75,7 @@
7575
"@storybook/addon-actions": "^5.3.19",
7676
"@storybook/addon-links": "^5.3.19",
7777
"@storybook/addons": "^5.3.19",
78+
"@storybook/node-logger": "^5.3.19",
7879
"@storybook/preset-create-react-app": "^3.1.4",
7980
"@storybook/react": "^5.3.19",
8081
"@types/axios": "^0.14.0",
@@ -109,6 +110,7 @@
109110
"@types/redux-logger": "^3.0.8",
110111
"@types/redux-mock-store": "^1.0.2",
111112
"@types/redux-thunk": "^2.1.0",
113+
"babel-loader": "^8.1.0",
112114
"body-parser": "^1.18.2",
113115
"cors": "^2.8.5",
114116
"cross-env": "^5.1.3",
@@ -127,6 +129,7 @@
127129
"react-scripts": "^3.4.1",
128130
"redux-logger": "^3.0.6",
129131
"redux-mock-store": "^1.5.1",
132+
"regenerator-runtime": "^0.13.7",
130133
"timekeeper": "^2.0.0",
131134
"ts-loader": "^6.2.2",
132135
"ts-node": "^8.8.1",

frontend/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@
23282328
dependencies:
23292329
lodash "^4.17.15"
23302330

2331-
"@storybook/[email protected]":
2331+
"@storybook/[email protected]", "@storybook/node-logger@^5.3.19":
23322332
version "5.3.19"
23332333
resolved "https://registry.npmjs.org/@storybook/node-logger/-/node-logger-5.3.19.tgz#c414e4d3781aeb06298715220012f552a36dff29"
23342334
integrity sha512-hKshig/u5Nj9fWy0OsyU04yqCxr0A9pydOHIassr4fpLAaePIN2YvqCqE2V+TxQHjZUnowSSIhbXrGt0DI5q2A==
@@ -4199,9 +4199,9 @@ babel-jest@^24.9.0:
41994199
chalk "^2.4.2"
42004200
slash "^2.0.0"
42014201

4202-
4202+
[email protected], babel-loader@^8.1.0:
42034203
version "8.1.0"
4204-
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.1.0.tgz#c611d5112bd5209abe8b9fa84c3e4da25275f1c3"
4204+
resolved "https://registry.npmjs.org/babel-loader/-/babel-loader-8.1.0.tgz#c611d5112bd5209abe8b9fa84c3e4da25275f1c3"
42054205
integrity sha512-7q7nC1tYOrqvUrN3LQK4GwSk/TQorZSOlO9C+RZDZpODgyN4ZlCqE5q9cDsyWOliN+aU9B4JX01xK9eJXowJLw==
42064206
dependencies:
42074207
find-cache-dir "^2.1.0"
@@ -15272,7 +15272,7 @@ regenerator-runtime@^0.11.0:
1527215272
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
1527315273
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==
1527415274

15275-
regenerator-runtime@^0.13.2:
15275+
regenerator-runtime@^0.13.2, regenerator-runtime@^0.13.7:
1527615276
version "0.13.7"
1527715277
resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
1527815278
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==

0 commit comments

Comments
 (0)