NOTE: This repo is deprecated and retained only for archival/informational purposes. The repo containing the current BC Developers' Exchange app is https://github.com/bcdevexchange/devex. Head over there to see the latest code.
The BCDevExchange website is the public facing site for the BC Developers' Exchange - an experiment in tech innovation and collaboration.
We are open to pull requests! See our contributing guide for the details.
This web app is built on the MEAN stack. The app has been retrofitted with Yeoman angular-fullstack generator except for a couple twists
- phasing out bower in favor of browserify. Going forward, any client-side JS library should be added in
package.json
instead ofbower.json
and included by means of CommonJS style whenever possible. - replaced server-side mocha unit test with Jasmine.
You'll need MongoDB, NodeJS, and Git. An IDE is optional. Clone this repo from GitHub, change directory to the repo root.
- Run
npm install
. - Install Grunt for the command line via
npm install -g grunt-cli
. - Adjust settings in
config/default.json
. For example, supply your client ID and secret for GitHub authentication. Instead of changingconfig/default.json
directly, create fileconfig/local.json
and put changes there. Config file loading order is described in module node-config. - Run
grunt serve
to start a Node server. Defaults to localhost:9000.
We use Grunt to automate some of the development process. Some notable tasks:
grunt serve
Launches site in development environment. No client-side optimization (js uglification etc) is performed to facilitate debugging.
grunt serve:debug
Enables Node debugger and launches node-inspector for server-side debugging. Node-inspector has been configured to disable source code discovery by default to speedup loading. Only executed code is available to Node-inspector. Therefore in order to set a breakpoint in a source file, you have to hit some web page that requires the source file first, then reload node-inspector in browser.
grunt serve:dist
Builds and launches site in production environment. Client-side optimization is performed as part of the build process.
grunt serve:dist-nobuild
Launches in production environment without build.
grunt build
Builds production environment without launching the site.
grunt
Performs server-side and client-side (Karma) unit testing, then builds production environment without launching the site.
We use Gulp to ensure that each appropriate file in the repo has a license file attached to it. These appear in the header of each appropriate file. To check if the license is on every appropriate file, run
gulp
To automatically update/insert license, use:
gulp --update
All test scripts are written in Jasmine 2 BDD format. BCDevExchange-app has 3 types of testing framework setup:
- Protractor for end-to-end testing. Run
grunt test:e2e
to launch tests. Test scripts resides in/e2e/**/*.spec.js
- Karma for client-side Angular unit testing. Run
grunt test:client
to launch tests. Test scripts resides in/client/app/**/*.spec.js
- grunt-jasmine-nodejs for server-side NodeJS unit testing. Run
grunt test:server
to launch tests. Test scripts resides in/server/**/*.spec.js
We use a Linux server with:
- nginx
- NodeJS via N Use version 0.12.x
- MongoDB
- Bind as a local DNS cache
Install forever globally using
sudo npm install -g forever
Next, set up the repo
git clone --branch <master or discovery> git://github.com/BCDevExchange/BCDevExchange-app.git
cd BCDevExchange
npm install --production
chmod +x foreverme.sh
You'll want to create a local configuration file in config called:
./config/local.json
Starting the NodeJS server in forever mode on bootup the rc.local way:
sudo -e /etc/rc.local
then add to the bottom:
sudo -u bitnami /bin/bash /home/bitnami/apps/lab/BCDevExchange-app/foreverme.sh
Stdout, stderr and forever logs are here:
<path to app root>/log/
Following regular nginx installation and feel free to use the sample configs are provided in under:
/config/nginx
Following regular MongoDB installation and create new DBs and user accounts. These names, usernames and passwords must be configured in your:
/config/local.conf
Navigate to the app root (e.g. /home/bitnami/apps/lab/BCDevExchange-app/
), then
git pull
npm install --production
forever list
forever restart <pid>
Where <pid>
is the process ID of the environment you want to restart.
First you'll need N installed:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Typically, you'll upgrade to latest stable:
sudo n stable
Test you have the right version now:
node -v
Then restart forever processes, post-install:
forever list
forever restart <pid>
Where <pid>
is the process ID of the environment you want to restart.
This is for setting up access to the Google Analytics API. Those who do not have access to BCDevExchange's Google Analytics account can skip this step. The site will function without Google Analytics set up.
-
Log into the Google account that has access to BCDevExchange's Google Analytics.
-
In the Developers Console, create a new project.
-
Under "APIs & auth", go to "APIs". Search for the "Analytics API" and enable it.
-
Next go to "Credentials". Create a new Client ID. Make sure to select "Service Account" and for the key type select "P12 Key". This will automatically download a
.p12
file to your computer, and the Developers Console will provide you with a password to access it (by default it should be "notasecret"). -
Make a note of the "Email address" field under your new "Service account". It should look like
[email protected]
. -
The
.p12
file needs to be converted to a.pem
file. Run the following command where your.p12
file is located:openssl pkcs12 -in XXXXX.p12 -nocerts -nodes -out XXXXX.pem
You will be prompted for a password. By default it should be "notasecret".
-
Add your
developer.gserviceaccount.com
email to the Google Analytics account with "Read & Analyze" access. -
Get the View ID from Google Analytics. This is found in the "Admin" section at the top, under the "View" category in "View Settings".
-
Lastly the configuration files need to be updated. Update
local.json
inside/config
. An example is provided below:
"google_analytics": {
"api_email": "[email protected]",
"analytics_view_id": "your-view-id",
"key_file": "/path/to/the/pem/file/key.pem"
}
We've benchmarked performance for this site as it was running on a Microsoft Azure Standard D1 (One Core) 4 GB RAM VM using a Bitnami packaged Ubuntu VM.
Static file serving (all Ngnix): 4000 req/sec
Dynamic resource serving (Nginx + NodeJS): 100 req/sec < 500ms
Copyright 2015 Province of British Columbia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
BCDevExchange-Project