Skip to content

Commit ac5fafe

Browse files
Allow passing additional redirects in the config
1 parent 79b8a41 commit ac5fafe

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@ ember install ember-cli-netlify
2121
Usage
2222
------------------------------------------------------------------------------
2323

24-
Just define a `.netlifyheaders` and/or a `.netlifyredirects` file in the root of your project and this
24+
### .netlifyheaders and/or .netlifyredirects
25+
26+
There are a couple ways to use this addon. The first one is to define a `.netlifyheaders`
27+
and/or a `.netlifyredirects` file in the root of your project and this
2528
addon will copy the output to `dist/_headers` and `dist/_redirects` respectively.
2629

30+
### ember-cli-build.js
31+
32+
The second way is to define an `ember-cli-netlify` hash in your `ember-cli-build.js`.
33+
You can combine these methods, and anything defined in the config hash will be
34+
appended to the existing files. Currently, only redirects are supported, not headers.
35+
36+
```js
37+
'ember-cli-netlify': {
38+
redirects: [
39+
'https://blog.shipshape.io/* https://shipshape.io/blog/:splat 301!',
40+
'https://blog.shipshape.io/* https://shipshape.io/blog/:splat 301!'
41+
]
42+
}
43+
```
44+
45+
2746
Contributing
2847
------------------------------------------------------------------------------
2948

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ const fs = require('fs-extra');
55
module.exports = {
66
name: require('./package').name,
77
outputReady() {
8+
const netlifyOptions = this.app.options['ember-cli-netlify'];
9+
810
if (fs.pathExistsSync('.netlifyheaders')) {
911
fs.copySync('.netlifyheaders', 'dist/_headers', { clobber: true });
1012
}
1113

1214
if (fs.pathExistsSync('.netlifyredirects')) {
1315
fs.copySync('.netlifyredirects', 'dist/_redirects', { clobber: true });
16+
} else if (netlifyOptions && netlifyOptions.redirects) {
17+
fs.writeFileSync('dist/_redirects');
18+
}
19+
20+
if (netlifyOptions && netlifyOptions.redirects) {
21+
const stream = fs.createWriteStream('dist/_redirects', { flags: 'a' });
22+
netlifyOptions.redirects.forEach((redirect) => {
23+
stream.write(`${redirect}\n`);
24+
});
25+
stream.end();
1426
}
1527
}
1628
};

0 commit comments

Comments
 (0)