Skip to content

Commit 1266cd3

Browse files
author
Jen Weber
authored
Draft content for deployments (#27)
* intro section * root url configuration * common deployment configurations * typo fix * Remove unnecessary comment * Update deploying.md * make alex linter happy * fix broken link
1 parent bab176a commit 1266cd3

File tree

2 files changed

+196
-2
lines changed

2 files changed

+196
-2
lines changed

.alexrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"allow": [
33
"host-hostess",
44
"watchman-watchwoman",
5-
"disabled"
5+
"disabled",
6+
"hooks",
7+
"attacks"
68
]
79
}

guides/basic-use/deploying.md

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,193 @@
1-
<!-- should show ember build, link to ember-cli-deploy, Guides tutorial -->
1+
No matter where you are deploying your app to, the Ember CLI and community ecosystem have tools to help. In this section of the guide, we will go over some general approaches and common configurations.
2+
3+
## Behind the scenes of deploying
4+
5+
No matter which framework you use, there are some processing steps that the code probably has to go through before it is ready to be shared on the internet. For some frameworks, you need to learn all these steps and choose your own toolset. However, thanks to the hard work of many contributors across the years, the Ember CLI and community tools already have these steps set up.
6+
7+
As a result, you may not need to understand or configure build steps, but it's still helpful to have some background knowledge and terminology. Here are some common steps that the Ember CLI handles for you:
8+
9+
- compilation - Instead of having dozens of files, many are combined together into a smaller number
10+
- minification and uglification - code is optimized for speedy evaluation by the browser, as opposed to human readability
11+
- transpilation - modern JavaScript APIs are not available in some browsers, but that doesn't have to stop developers! Tools like Babel are used by many frameworks to turn newer JavaScript into code that still runs in older browsers.
12+
- transformations - things like stripping out code comments
13+
14+
## How to deploy
15+
16+
Behind the scenes, deploying an app has two steps: building the app for production and pushing the result to a web server for hosting.
17+
18+
There are three main options for deploying your app: using the `ember build` command, installing `ember-cli-deploy`, or using pre-made build packs.
19+
20+
### `ember build` and upload
21+
22+
If you already have a hosting plan in mind, you can build the app from the command line and then use `scp` or `rsync` to upload the files.
23+
24+
It's important to set the environment to `production` so that your app receives the right treatment for minification and fingerprinting:
25+
26+
```bash
27+
ember build --environment=production
28+
```
29+
30+
The results of the `build` command are placed in the `dist` directory within your project.
31+
32+
For a tutorial that shows how to build your app and upload it to a web host using `scp` and `rsync`, see the [Official Ember.js Tutorial](https://guides.emberjs.com/release/tutorial/deploying/).
33+
34+
### Ember CLI Deploy
35+
36+
[ember-cli-deploy](http://ember-cli-deploy.com/) is a very popular community-built addon for the Ember CLI. What this means is that it's not built into the CLI by default, but it adds commands and configurations that should feel familiar to an Ember developer. The main benefit is that you set it up once and may never have to think about it again.
37+
38+
`ember-cli-deploy` provides the `ember deploy` command, some build hooks, and configuration files to your project. There are many [`ember-cli-deploy` plugins](https://www.emberobserver.com/categories/ember-cli-deploy-plugins) that help you deploy to many diffent destinations and web hosting services, such as AWS S3 or GitHub pages.
39+
40+
The best way to get started using ember-cli-deploy is to visit the [documentation](http://ember-cli-deploy.com/) for the project.
41+
42+
### Using Build Packs
43+
44+
Some hosting service providers offer automated deployment in other ways.
45+
For example, Heroku has a build pack and CLI of their own that provides a zero-config deployment! The step-by-step examples are available at [https://www.heroku.com/emberjs](https://www.heroku.com/emberjs)
46+
47+
Do you know of any other hosting services that make it easy to deploy Ember apps?
48+
Please [open an issue](https://github.com/ember-learn/cli-guides-source) for this Guide.
49+
50+
## Common deployment configurations
51+
52+
Compared to develping an app locally, there are some options to consider when an app is in deployment. Some apps may not need to make any of these configurations, but here are just a few of the most common examples to help you get started. For more details, see the [Advanced Use](../../advanced-use/) section of the CLI guides.
53+
54+
### Configuring `rootURL`
55+
56+
<!-- older docs reference the "History API". Is that still a thing? I took it out. (Jen) -->
57+
58+
Many Ember apps are served from the index of a domain, like `https://some-domain-name.com/`, which requres no configuration. However, if an app is served from somewhere other than the root `/` of the domain, like `https://some-domain-name.com/path/to/ember/app/`
59+
you will need to configure the value of `rootURL` in `config/environment.js`.
60+
This is required for Router to function correctly.
61+
62+
Here's an example of configuring rootURL:
63+
64+
```javascript
65+
// config/environment.js
66+
if (environment === 'production') {
67+
ENV.rootURL = '/path/to/ember/app/';
68+
}
69+
```
70+
71+
The `rootURL` is used as a prefix for assets, eg `/path/to/ember/app/assets/vendor.js`. However when
72+
building for production, the value of `prepend` for `fingerprint` will be used instead.
73+
74+
Here's an example of building for production and using the `fingerprint` and `prepend` configuration. The asset URLs will not use `rootURL`. Instead, the result will be
75+
`https://cdn.example.com/assets/vendor-3b1b39893d8e34a6d0bd44095afcd5c4.js`.
76+
77+
```bash
78+
ember build environment=production
79+
```
80+
81+
```javascript
82+
// ember-cli-build.js
83+
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
84+
85+
module.exports = function(defaults) {
86+
let app = new EmberApp(defaults, {
87+
// Add options here
88+
fingerprint: {
89+
prepend: 'https://cdn.example.com/'
90+
}
91+
});
92+
93+
return app.toTree();
94+
};
95+
```
96+
97+
Lastly, if you find yourself working with an older app, you may see references to `baseURL` rather than `rootURL`. `baseURL` was deprecated in 2.7 and removed in Ember 3.
98+
99+
### Content Security Policy
100+
101+
It is best practice to define a Content Security Policy for your application, even for local development, and to make it restrictive. That way security violations can be discovered immediately.
102+
103+
A Content Security Policy configuration defines the list of places that your app should accept data from. For example, an app may allow stylesheets from a CDN and images from a specific data storage service.
104+
105+
The Content Security Policy can be set in `environment.js`:
106+
107+
```javascript
108+
module.exports = function(environment) {
109+
let ENV = {
110+
...
111+
contentSecurityPolicy: {
112+
'default-src': "'self'",
113+
'script-src': "'self' *.my-domain-name.com",
114+
'font-src': "'self' fonts.googleapis.com fonts.gstatic.com",
115+
'connect-src': "'self' my-auth-provider.com",
116+
'img-src': "self",
117+
'style-src': "self",
118+
'media-src': "self"
119+
}
120+
};
121+
...
122+
}
123+
```
124+
125+
<!-- we need to inline some of this info
126+
For more information, see the [`ember-cli-content-security-policy` README.]( https://github.com/rwjblue/ember-cli-content-security-policy)
127+
-->
128+
129+
### Serving your app securely across HTTPS
130+
131+
The use of HTTPS certificates is best practice for web security and professionalism of any deployed apps for any framework. It is outside the scope of this guide to go into detail about how to manage HTTPS certificates, redirects, and web hosting details. However, front end developers should be aware of security best practices and have a few hints to help them move in the right direction.
132+
133+
Plain old HTTP sites are likely to show your users security warnings and they are vulnerable to man-in-the-middle attacks. HTTPS certificates are available at no cost from many identity and hosting providers. However, even if you have an HTTPS certificate, you will still need a way to redirect any users who visit `http://your-ember-app.com`, for example.
134+
135+
The following is a simple http-to-https redirect using [nginx](). Don't forget to include your ssl keys in your config.
136+
137+
First, make a production build of your app. The results will be saved in the `dist` directory:
138+
139+
```bash
140+
ember build --environment=production
141+
```
142+
143+
<!-- Where does this file go, exactly? -->
144+
Then, define an `nginx.conf` to be used on your server:
145+
146+
```text
147+
#### File: nginx.conf
148+
149+
## Nginx Production Https Ember Server Configuration
150+
151+
## https site##
152+
server {
153+
listen 443 default;
154+
server_name <your-server-name>;
155+
#root /usr/share/nginx/html;
156+
root <root path to an ember /dist directory>;
157+
index index.html index.htm;
158+
159+
# log files
160+
access_log /var/log/nginx/<your-server-name>.access.log;
161+
error_log /var/log/nginx/<your-server-name>.error.log;
162+
163+
# ssl files
164+
ssl on;
165+
keepalive_timeout 60;
166+
167+
# include information on SSL keys, cert, protocols and ciphers
168+
# SSLLabs.com is a great resource for this, along with testing
169+
# your SSL configuration: https://www.ssllabs.com/projects/documentation/
170+
171+
# Strict Transport Security
172+
add_header Strict-Transport-Security max-age=2592000;
173+
174+
# proxy buffers
175+
proxy_buffers 16 64k;
176+
proxy_buffer_size 128k;
177+
178+
## default location ##
179+
location / {
180+
include /etc/nginx/mime.types;
181+
try_files $uri $uri/ /index.html?/$request_uri;
182+
}
183+
184+
}
185+
186+
## http redirects to https ##
187+
server {
188+
listen 80;
189+
server_name <your-server-name>;
190+
191+
rewrite ^/.*$ https://$host$request_uri? permanent;
192+
}
193+
```

0 commit comments

Comments
 (0)