From 178b3a7a56a8ef0dcb13ad81d36e3c7778addf00 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 11:47:51 -0300 Subject: [PATCH 1/8] playground-server: passing webpack config to build --- packages/playground-server/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index c5acf5d0e..3f3f5eed3 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -22,7 +22,7 @@ }, "scripts": { "start": "netlify-lambda -c webpack.config.js serve src", - "build": "netlify-lambda build src", + "build": "netlify-lambda -c webpack.config.js build src", "test": "jest" }, "bugs": { From 4591fa2fa3d1fab3a42ef719f6d2fe6536f9944a Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 12:06:25 -0300 Subject: [PATCH 2/8] playground-server: fixed local routing issues --- packages/playground-server/package.json | 3 ++- packages/playground-server/src/api.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 3f3f5eed3..423f1072e 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -23,7 +23,8 @@ "scripts": { "start": "netlify-lambda -c webpack.config.js serve src", "build": "netlify-lambda -c webpack.config.js build src", - "test": "jest" + "dev": "NODE_ENV=dev netlify-lambda -c webpack.config.js serve src", + "test": "NODE_ENV=dev jest" }, "bugs": { "url": "https://github.com/counterfactual/monorepo/issues" diff --git a/packages/playground-server/src/api.ts b/packages/playground-server/src/api.ts index f9c106d54..6f8e48f2d 100644 --- a/packages/playground-server/src/api.ts +++ b/packages/playground-server/src/api.ts @@ -6,9 +6,16 @@ import bodyParser from "koa-body"; import Router from "koa-router"; const app = new Koa(); + const router = new Router(); -router.get("/api/hello", async (ctx, next) => { +if (process.env.NODE_ENV !== "development") { + router.prefix("/.netlify/functions/api"); +} else { + router.prefix("/api"); +} + +router.get("/hello", async (ctx, next) => { ctx.body = { hello: ctx.request.query.name }; ctx.status = 200; return next(); From 40aa8c8c5ac1699fd404a7db4743a6ca377c627a Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 12:19:56 -0300 Subject: [PATCH 3/8] playground-server: fixed environment name --- packages/playground-server/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 423f1072e..99e4737f7 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -23,8 +23,8 @@ "scripts": { "start": "netlify-lambda -c webpack.config.js serve src", "build": "netlify-lambda -c webpack.config.js build src", - "dev": "NODE_ENV=dev netlify-lambda -c webpack.config.js serve src", - "test": "NODE_ENV=dev jest" + "dev": "NODE_ENV=development netlify-lambda -c webpack.config.js serve src", + "test": "NODE_ENV=development jest" }, "bugs": { "url": "https://github.com/counterfactual/monorepo/issues" From 2877b2ac514e0ffd7e5d01cba1c0b8f62a82c809 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 12:35:07 -0300 Subject: [PATCH 4/8] playground-server: forcing Netlify to ack productive env --- packages/playground-server/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 99e4737f7..9876cb17d 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -21,8 +21,8 @@ "url": "git+https://github.com/counterfactual/monorepo.git" }, "scripts": { - "start": "netlify-lambda -c webpack.config.js serve src", - "build": "netlify-lambda -c webpack.config.js build src", + "start": "NODE_ENV=production netlify-lambda -c webpack.config.js serve src", + "build": "NODE_ENV=production netlify-lambda -c webpack.config.js build src", "dev": "NODE_ENV=development netlify-lambda -c webpack.config.js serve src", "test": "NODE_ENV=development jest" }, From cce6b1e4751d6c42549a15e3040141b52358e7c4 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 12:42:53 -0300 Subject: [PATCH 5/8] playground-server: adding DEBUG=* to see where the router breaks --- packages/playground-server/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 9876cb17d..0ec552caf 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -21,8 +21,8 @@ "url": "git+https://github.com/counterfactual/monorepo.git" }, "scripts": { - "start": "NODE_ENV=production netlify-lambda -c webpack.config.js serve src", - "build": "NODE_ENV=production netlify-lambda -c webpack.config.js build src", + "start": "DEBUG=* NODE_ENV=production netlify-lambda -c webpack.config.js serve src", + "build": "DEBUG=* NODE_ENV=production netlify-lambda -c webpack.config.js build src", "dev": "NODE_ENV=development netlify-lambda -c webpack.config.js serve src", "test": "NODE_ENV=development jest" }, From 57c2c6f1c5cfcccf1e4a055e8b5e733db5c72b60 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 14:58:12 -0300 Subject: [PATCH 6/8] playground-server: added some console.log()'s to debug --- packages/playground-server/src/api.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/playground-server/src/api.ts b/packages/playground-server/src/api.ts index 6f8e48f2d..ac89e87b8 100644 --- a/packages/playground-server/src/api.ts +++ b/packages/playground-server/src/api.ts @@ -11,11 +11,14 @@ const router = new Router(); if (process.env.NODE_ENV !== "development") { router.prefix("/.netlify/functions/api"); + console.log("prefixing with /.netlify/functions/api"); } else { router.prefix("/api"); + console.log("prefixing with /api"); } router.get("/hello", async (ctx, next) => { + console.log("entering middleware: hello"); ctx.body = { hello: ctx.request.query.name }; ctx.status = 200; return next(); From e716dd19b40dca1d77d4617d165010ec9faf68c2 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Wed, 26 Dec 2018 15:12:59 -0300 Subject: [PATCH 7/8] playground-server: fixed env-var bug (see netlify/netlify-lambda#59) --- packages/playground-server/package.json | 4 ++-- packages/playground-server/src/api.ts | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 0ec552caf..99e4737f7 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -21,8 +21,8 @@ "url": "git+https://github.com/counterfactual/monorepo.git" }, "scripts": { - "start": "DEBUG=* NODE_ENV=production netlify-lambda -c webpack.config.js serve src", - "build": "DEBUG=* NODE_ENV=production netlify-lambda -c webpack.config.js build src", + "start": "netlify-lambda -c webpack.config.js serve src", + "build": "netlify-lambda -c webpack.config.js build src", "dev": "NODE_ENV=development netlify-lambda -c webpack.config.js serve src", "test": "NODE_ENV=development jest" }, diff --git a/packages/playground-server/src/api.ts b/packages/playground-server/src/api.ts index ac89e87b8..6f8e48f2d 100644 --- a/packages/playground-server/src/api.ts +++ b/packages/playground-server/src/api.ts @@ -11,14 +11,11 @@ const router = new Router(); if (process.env.NODE_ENV !== "development") { router.prefix("/.netlify/functions/api"); - console.log("prefixing with /.netlify/functions/api"); } else { router.prefix("/api"); - console.log("prefixing with /api"); } router.get("/hello", async (ctx, next) => { - console.log("entering middleware: hello"); ctx.body = { hello: ctx.request.query.name }; ctx.status = 200; return next(); From 827de6ec644e7c01448cab63c7af841984f7c699 Mon Sep 17 00:00:00 2001 From: Joel Alejandro Villarreal Bertoldi Date: Thu, 27 Dec 2018 08:57:04 -0300 Subject: [PATCH 8/8] playground-server: replace NODE_ENV with PLAYGROUND_SERVER_ENV --- packages/playground-server/package.json | 8 ++++---- packages/playground-server/src/api.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index 99e4737f7..aa17865cf 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -21,10 +21,10 @@ "url": "git+https://github.com/counterfactual/monorepo.git" }, "scripts": { - "start": "netlify-lambda -c webpack.config.js serve src", - "build": "netlify-lambda -c webpack.config.js build src", - "dev": "NODE_ENV=development netlify-lambda -c webpack.config.js serve src", - "test": "NODE_ENV=development jest" + "start": "PLAYGROUND_SERVER_ENV=production netlify-lambda -c webpack.config.js serve src", + "build": "PLAYGROUND_SERVER_ENV=production netlify-lambda -c webpack.config.js build src", + "dev": "PLAYGROUND_SERVER_ENV=development netlify-lambda -c webpack.config.js serve src", + "test": "PLAYGROUND_SERVER_ENV=development jest" }, "bugs": { "url": "https://github.com/counterfactual/monorepo/issues" diff --git a/packages/playground-server/src/api.ts b/packages/playground-server/src/api.ts index 6f8e48f2d..52cd40413 100644 --- a/packages/playground-server/src/api.ts +++ b/packages/playground-server/src/api.ts @@ -1,15 +1,14 @@ -import serverless from "serverless-http"; - import cors from "@koa/cors"; import Koa from "koa"; import bodyParser from "koa-body"; import Router from "koa-router"; +import serverless from "serverless-http"; const app = new Koa(); const router = new Router(); -if (process.env.NODE_ENV !== "development") { +if (process.env.PLAYGROUND_SERVER_ENV !== "development") { router.prefix("/.netlify/functions/api"); } else { router.prefix("/api");