This repository turns the angular quickstart into a Hapi plugin. It is meant to be a stating point for projects to host Angular 4 application from a Hapi server.
Useful commands to get up and running are included in npm scripts defined in the package.json
:
- "build": "tsc -p angular-4-quickstart",
- "serve": "nodemon server.js",
- "start": "concurrently "npm run build:watch" "npm run serve""
Changes from Quickstart:
- This is a Hapi app, so lite-server is not necessary.
- nodemon is used to keep the server running until it is canceled from the command line with
ctrl-c
/cmd-c
.tsconfig.json
has been relocated with the app. This means thattsc
needs to be giving a--project
or-p
argument. Seenpm run build
.
An index.js
file has been added to the root directory of the Angular app, which allows us to perform the require()
needed to register the plugin in server.js
.
server.register({
register: require('./angular-4-quickstart')
})
I've provided an example of how to add another plugin, let's say a back end REST API for instance:
server.register({
register: require('./backend'),
routes: { prefix: 'api' }
})
The angular-4-quickstart
plugin provides routes in four different ways, which permits the client app access to all of the files it needs to run:
- A shortcut to the app specifying '/' - serves
index.html
directly - Serves
index.html
,styles.css
,systemjs.config.js
directly - Server all public files under in the root Angular directory.
- Serves all necessary files in the
/node_modules
directory
The index.js
provided should be sufficient to get any Angular app up and running. Just drop it in to the root folder of the Angular app, and register it as a plugin.
Use the routes: { prefix: '<your app url>' }
option to host the app wherever you want.
hapi-angular-quickstart (for Angular 2).