Below are instructions for hosting and building the site and a layout of how the code is organized.
CNX webview is designed to be run as a frontend for cnx-archive.
- If necessary, install Node.js and npm (included with Node.js).
- Run
npm install --global nto install the node version manager - Run
./script/bootstrapin the command line to install all the package dependencies.
- Note:
npm installrunsbower installandgrunt install, both of which can also be run independentlybower installdownloads front-end dependenciesgrunt installcompiles the Aloha-Editor (which is downloaded by bower)
By default, webview will use cnx-archive and cnx-authoring hosted on cnx.org.
From the root webview directory, run ./script/setup.
The dist directory containing the built site will be added to the root webview directory.
From the root webview directory, run ./script/test (which runs npm test).
npm test failures are not as informative as they could be.
If coffeelint fails, you can run it with grunt coffeelint to get more information
From the root webview directory, run ./script/update, which executes the following commands:
npm updatebower updategrunt aloha --verbose
- Install nginx
- Run
./script/start(usesnginx.development.conf) - (optional) Install https://github.com/prerender/prerender
- Point your browser to http://localhost:8000
- Run
./script/stopto stop nginx
-
Update settings in
src/scripts/settings.jsif necessary to, for example, include the correct Google Analytics ID, and to point to wherevercnxarchiveis being hosted. -
Ensure resources are being served with the correct MIME type, including fonts.
- Example nginx MIME types that may need to be added:
types {
image/svg+xml svg svgz;
font/truetype ttf;
font/opentype otf;
application/font-woff woff;
}- Configure your server to point at
dist/index.html(orsrc/index.htmlfor development)
- Unresolveable URIs should load
dist/index.htmlorsrc/index.html - If not hosting the site from the domain root, update
rootinsrc/scripts/settings.js scripts,styles, andimagesroutes should be rewritten to the correct paths
Example nginx config
server {
listen 8000; # dev
listen [::]:8000; # dev ipv6
listen 8001; # production
listen [::]:8001; # production ipv6
server_name _;
# Support both production and dev
set $ROOT "src";
if ($server_port ~ "8001") {
set $ROOT "dist";
}
root /path/to/webview/$ROOT/;
index index.html;
try_files $uri @prerender;
# Proxy resources and exports to cnx.org
# since they are not part of the locally hosted package
location /resources/ {
proxy_pass http://cnx.org;
}
location /exports/ {
proxy_pass http://cnx.org;
}
# For development only
location ~ ^.*/bower_components/(.*)$ {
alias /path/to/webview/bower_components/$1;
}
location ~ ^.*/(data|scripts|styles|images|fonts)/(.*) {
try_files $uri /$1/$2;
}
# Prerender for SEO
location @prerender {
# Support page prerendering for web crawlers
set $prerender 0;
if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
if ($uri ~ "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent)") {
set $prerender 0;
}
if ($prerender = 1) {
rewrite .* /$scheme://$http_host$request_uri? break;
proxy_pass http://localhost:3000;
}
if ($prerender = 0) {
rewrite .* /index.html break;
}
}
}
bower_components/3rd Party Libraries (added after install)node_modules/Node Modules (added after install)dist/Production version of the site (added after build)src/Development version of the sitesrc/data/Hardcoded datasrc/images/Images used throughout the sitesrc/scripts/Site scripts and 3rd party librariessrc/scripts/collectionsBackbone Collectionssrc/scripts/helpersHelpers for Handlebars, Backbone, and generic codesrc/scripts/modelsBackbone Modelssrc/scripts/modulesSelf-contained, reusable Modules used to construct pagessrc/scripts/pagesBackbone Views representing an entire page (or the entire viewport)src/scripts/config.jsRequire.js configurationsrc/scripts/loader.coffeeApp loader, responsible for setting up global listenerssrc/scripts/main.jsInitial script called by Requirejssrc/scripts/router.coffeeBackbone Routersrc/scripts/session.coffeeSession state singleton (Backbone Model)src/scripts/settings.jsGlobal application config settings (remains in place after build)src/styles/App-specific LESS variables and mixinssrc/index.htmlApp's HTML Pagetest/Unit tests
This software is subject to the provisions of the GNU Affero General Public License Version 3.0 (AGPL). See license.txt for details. Copyright (c) 2013 Rice University.