Skip to content

Commit

Permalink
Merge pull request #81 from MatthewAlner/angular-proxy-documentation
Browse files Browse the repository at this point in the history
Add Angular Proxy Documentation
  • Loading branch information
swyxio authored Nov 25, 2018
2 parents e97a940 + df08ff5 commit 49bc518
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,51 @@ module.exports = {

The serving port can be changed with the `-p`/`--port` option.

## Using with `Angular CLI`

CORS issues when trying to use netlify-lambdas locally with angular? you need to set up a proxy.

Firstly make sure you are using relative paths in your app to ensure that your app will work locally and on Netlify, example below...

```js
this.http.get('/.netlify/functions/jokeTypescript')
```

Then place a `proxy.config.json` file in the root of your project, the contents should look something like...

```json
{
"/.netlify/functions/*": {
"target": "http://localhost:9000",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
```

- The `key` should match up with the location of your Transpiled `functions` as defined in your `netlify.toml`
- The `target` should match the port that the lambdas are being served on (:9000 by default)

When you run up your Angular project you need to pass in the proxy config with the flag `--proxy-config` like so...

```bash
ng serve --proxy-config proxy.config.json
```

To make your life easier you can add these to your `scripts` in `package.json`

```json
"scripts": {
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build --prod --aot && yarn nlb",
"nls": "netlify-lambda serve src_functions",
"nlb": "netlify-lambda build src_functions"
}
```

Obviously you need to run up `netlify-lambda` & `angular` at the same time.

## Webpack Configuration

By default the webpack configuration uses `babel-loader` to load all js files. Any `.babelrc` in the directory `netlify-lambda` is run from will be respected. If no `.babelrc` is found, a [few basic settings are used](https://github.com/netlify/netlify-lambda/blob/master/lib/build.js#L11-L15a).
Expand Down

0 comments on commit 49bc518

Please sign in to comment.