zewa666 / aurelia-node

An example of using Aurelia with a NodeJS Express App
36 stars 14 forks source link

Perhaps a note in the README.md is needed ... #7

Closed adriatic closed 9 years ago

adriatic commented 9 years ago

I cloned this repository on my (Windows) machine, and did everything that README.md files tells me to do. No hiccups, everything went completely smooth - and as a consequence I got the well known Aurelia Navigation Skeleton running.

Only then I checked the actual code and discovered several gems:

  1. bin/install: Github API node application that fetches the whole Aurelia Navigation Skeleton application from github _Why is the .js extenstion
  2. root level: app.js - another node application which gets invoked because of its name ( the default name for Aurelia Bootstrapper which is invoked because of the index.html having the section
   ...
   <script src="jspm_packages/system.js"></script>
    <script src="config.js"></script>
    <script>
      System.import('aurelia-bootstrapper');
    </script>
    ...

I also have a question: How is it achieved that the public/app/index.html gets processed when node runs the app.js

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var swig = require('swig');

var app = express();

var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');

    next();
};

// view engine setup
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(allowCrossDomain);
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

var api = require('./routes/api');
app.use('/', api);

var debug = require('debug')('aurelia-node');

app.set('port', process.env.PORT || 9000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

My final feedback: many aspects of this repository need to be explained to the benefit of others (folks who are not members of the core team, since if core team members are targeted "audience", I see no need for any documentation at all. :-)

zewa666 commented 9 years ago

Good questions but the thing is that this isn't really related to Aurelia itself but more a general way to develop node applications. So most of those information are available when looking for Node tutorials etc. Nevertheless lets give it a try:

Reg. bin/install (without .js extension) things stored in the bin folder are treated as executables, which you'd e.g. give execute permissions on linux. So whatever is in there may be started via node bin/name or shorter bin/name. Take a look here http://liangzan.net/blog/blog/2012/07/30/how-to-write-a-command-line-application-in-node-dot-js/

Reg. root app.js You are free to name your node apps entry file whatever you like, but a general approach is to name it app.js or index.js

Reg. public app.js as initial root Now this here is specific to ExpressJS, the library used for routing. To get detailed information please visit http://expressjs.com/ In short, in order to make the public app start by default this example performs an automatic redirect on initial startup as seen here https://github.com/zewa666/aurelia-node/blob/master/routes/api.js#L9-L11

Final remarks: this example is not targeting anyone in specific but shared as a general example for whoever needs it. It's not an official Aurelia repository nor the only way Aurelia recommends to do it. In fact there are some other implementations out there in the wild. The reason I've created this is that a lot of people started asking how to create a starting app with node + aurelia. So this should help you get running and focusing on Aurelia instead of how to setup node apps.

zewa666 commented 9 years ago

I'm going to close this one, if there is more needed we can reopen this again