Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

Commit

Permalink
[playground-server] Adds extra Webpack configuration to build process (
Browse files Browse the repository at this point in the history
…#377)

* playground-server: passing webpack config to build

* playground-server: fixed local routing issues

* playground-server: fixed environment name

* playground-server: forcing Netlify to ack productive env

* playground-server: adding DEBUG=* to see where the router breaks

* playground-server: added some console.log()'s to debug

* playground-server: fixed env-var bug (see netlify/netlify-lambda#59)

* playground-server: replace NODE_ENV with PLAYGROUND_SERVER_ENV
  • Loading branch information
joelalejandro authored Dec 27, 2018
1 parent adfbadf commit 1709622
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/playground-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions packages/playground-server/src/api.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 1709622

Please sign in to comment.