This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify the npm start script for running the app
* package.json * Replace the development server start command with a cli start script * start.sh * Can start server through either node or ng * Use npm start for production node execution * Use npm start -- -d for starting using 'ng serve' * server.js * Scaffold the angular compiled artefacts in the dist/ directory as static files in express to allow them to be server through node.
- Loading branch information
1 parent
4686e07
commit b276fa1
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var express = require("express"); | ||
var bodyParser = require("body-parser"); | ||
|
||
var app = express(); | ||
app.use(bodyParser.json()); | ||
|
||
// Create link to Angular build directory | ||
var distDir = __dirname + "/dist/"; | ||
app.use(express.static(distDir)); | ||
|
||
// Initialize the app. | ||
var server = app.listen(process.env.PORT || 8080, function () { | ||
var port = server.address().port; | ||
console.log("App now running on port", port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
################# | ||
# | ||
# Show help and exit | ||
# | ||
################# | ||
function show_help { | ||
echo "Usage: $0 [-d] [-h]" | ||
echo "-d: run in development mode" | ||
echo "" | ||
echo "To passthrough additional arguments, enter '--' followed by the extra arguments" | ||
exit 1 | ||
} | ||
|
||
# | ||
# Determine the command line options | ||
# | ||
while getopts ":d" opt; | ||
do | ||
case $opt in | ||
d) DEV=1 ;; | ||
h) show_help ;; | ||
esac | ||
done | ||
shift "$(expr $OPTIND - 1)" | ||
|
||
if [ "${DEV}" == "1" ]; then | ||
ng serve --host 0.0.0.0 --port 8080 --disable-host-check | ||
else | ||
ng build && node ./server.js | ||
fi |