diff --git a/packages/playground-server/package.json b/packages/playground-server/package.json index c5acf5d0e..aa17865cf 100644 --- a/packages/playground-server/package.json +++ b/packages/playground-server/package.json @@ -21,9 +21,10 @@ "url": "git+https://github.com/counterfactual/monorepo.git" }, "scripts": { - "start": "netlify-lambda -c webpack.config.js serve src", - "build": "netlify-lambda build src", - "test": "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 f9c106d54..52cd40413 100644 --- a/packages/playground-server/src/api.ts +++ b/packages/playground-server/src/api.ts @@ -1,14 +1,20 @@ -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(); -router.get("/api/hello", async (ctx, next) => { +if (process.env.PLAYGROUND_SERVER_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();