Skip to content

Commit 49bc518

Browse files
authored
Merge pull request #81 from MatthewAlner/angular-proxy-documentation
Add Angular Proxy Documentation
2 parents e97a940 + df08ff5 commit 49bc518

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,51 @@ module.exports = {
7272

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

75+
## Using with `Angular CLI`
76+
77+
CORS issues when trying to use netlify-lambdas locally with angular? you need to set up a proxy.
78+
79+
Firstly make sure you are using relative paths in your app to ensure that your app will work locally and on Netlify, example below...
80+
81+
```js
82+
this.http.get('/.netlify/functions/jokeTypescript')
83+
```
84+
85+
Then place a `proxy.config.json` file in the root of your project, the contents should look something like...
86+
87+
```json
88+
{
89+
"/.netlify/functions/*": {
90+
"target": "http://localhost:9000",
91+
"secure": false,
92+
"logLevel": "debug",
93+
"changeOrigin": true
94+
}
95+
}
96+
```
97+
98+
- The `key` should match up with the location of your Transpiled `functions` as defined in your `netlify.toml`
99+
- The `target` should match the port that the lambdas are being served on (:9000 by default)
100+
101+
When you run up your Angular project you need to pass in the proxy config with the flag `--proxy-config` like so...
102+
103+
```bash
104+
ng serve --proxy-config proxy.config.json
105+
```
106+
107+
To make your life easier you can add these to your `scripts` in `package.json`
108+
109+
```json
110+
"scripts": {
111+
"start": "ng serve --proxy-config proxy.config.json",
112+
"build": "ng build --prod --aot && yarn nlb",
113+
"nls": "netlify-lambda serve src_functions",
114+
"nlb": "netlify-lambda build src_functions"
115+
}
116+
```
117+
118+
Obviously you need to run up `netlify-lambda` & `angular` at the same time.
119+
75120
## Webpack Configuration
76121

77122
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).

0 commit comments

Comments
 (0)