This guide shows you how to deploy an Angular application to Edgio.
Connector
This framework has a connector developed for Edgio. See Connectors for more information.
Prerequisites
Setup requires:
- An Edgio account. Sign up for free.
- An Edgio property. Learn how to create a property.
- Node.js. View supported versions and installation steps.
- Edgio CLI.
Install the Edgio CLI
If you have not already done so, install the Edgio CLI.
Bash
1npm i -g @edgio/cli@latest
Getting Started
If you don’t already have an Angular application, you can create one using the following steps:
1. Create a new Angular App
Bash
1npm install -g @angular/cli2ng new my-edgio-angular-app
You should now have a working starter app. Run
ng serve
to see the application running on localhost:4200
.2. Initializing your Project
Initialize your project for use with Edgio by running the following command in your project’s root directory:
Bash
1edgio init --edgioVersion latest
This will automatically add all of the required dependencies and files to your project. These include:
- The
@edgio/core
package - The
@edgio/connectors
package - The
@edgio/cli
package edgio.config.js
- Contains various configuration options for Edgio.routes.js
- A default routes file that sends all requests to the Angular Universal server. Update this file to add caching or proxy some URLs to a different origin.
3. Use the right angular project
If you have several projects and the
defaultProject
as specified in angular.json
is not the project with the SSR build, specify the correct project with the ANGULAR_PROJECT
environment variable. For example: ANGULAR_PROJECT=my-ssr-project edgio build
.Routing
The default
routes.js
file created by edgio init
sends all requests to Angular server via a fallback route.JavaScript
1// This file was added by edgio init.2// You should commit this file to source control.34const { Router } = require('@edgio/core/router')5const { connectorRoutes } = require('@edgio/connectors')67module.exports = new Router().use(connectorRoutes)
Running Locally
To test your app locally, run:
Bash
1edgio dev
You can do a production build of your app and test it locally using:
Bash
1edgio build && edgio run --production
Setting
--production
runs your app exactly as it will be when deployed to the Edgio cloud.If you have several projects and the
defaultProject
in angular.json
is not the project you would like to deploy, specify the correct project by setting the ANGULAR_PROJECT
environment variable when running edgio run
.For example:
Bash
1ANGULAR_PROJECT=my-project edgio run --production
Deploying
Deploy your app to the Sites by running the following command in your project’s root directory:
Bash
1edgio deploy
Your initial CDN-as-code deployment will generate system-defined origin configurations along with those defined within your
edgio.config.js
. Learn more about system-defined origins.If you have several projects and the
defaultProject
in angular.json
is not the project you would like to deploy, specify the correct project by setting the ANGULAR_PROJECT
environment variable when running edgio deploy
.For example:
JSON
1ANGULAR_PROJECT=my-project edgio deploy
See Deployments for more information.