1 | var express = require('express'),
|
2 | Moonboots = require('./index.js'),
|
3 | app = express();
|
4 |
|
5 | // configure our app
|
6 | var clientApp = new Moonboots({
|
7 | main: __dirname + '/sample/app/app.js',
|
8 | templateFile: __dirname + '/sample/app.html',
|
9 | modulesDir: __dirname + '/sample/modules',
|
10 | developmentMode: true,
|
11 | libraries: [
|
12 | __dirname + '/sample/libraries/jquery.js'
|
13 | ],
|
14 | stylesheets: [
|
15 | __dirname + '/sample/stylesheets/style.css',
|
16 | __dirname + '/sample/stylesheets/app.css'
|
17 | ],
|
18 | beforeBuildCSS: function () {
|
19 | console.log('Before build CSS');
|
20 | },
|
21 | beforeBuildJS: function (cb) {
|
22 | // Simulating an async build step
|
23 | setTimeout(function () {
|
24 | console.log('Before build JS');
|
25 | cb();
|
26 | }, 2000);
|
27 | },
|
28 | server: app
|
29 | });
|
30 |
|
31 | // We can choose to not run a server, but instead just
|
32 | // write the files to a directory. If we ran the script
|
33 | // with `node server.js --build` then our files will be
|
34 | // buil5 and saved to ./build with developmentMode
|
35 | // turned off and the script will exit
|
36 | if (!!process.argv.join(' ').indexOf(' --build')) {
|
37 | clientApp.config.developmentMode = false;
|
38 | clientApp.build(__dirname + '/sample-build');
|
39 | return;
|
40 | }
|
41 |
|
42 | // if we want to prime the user's cache with the
|
43 | // application files. The login page is a great place
|
44 | // to do this. We can retrieve the name of the
|
45 | // JS file for the current app, by calling module's
|
46 | // jsFileName() function.
|
47 | app.get('/login', function (req, res) {
|
48 | // then in our login page we can lazy load the application to
|
49 | // prime the user's cache while they're typing in their username/password
|
50 | res.render('login', {appFileName: clientApp.jsFileName()});
|
51 | });
|
52 |
|
53 | // We also just need to specify the routes at which we want to serve this clientside app.
|
54 | // This is important for supporting "deep linking" into a single page app. The server
|
55 | // has to know what urls to let the browser app handle.
|
56 | app.get('*', clientApp.html());
|
57 |
|
58 | // start listening for http requests
|
59 | app.listen(3000, function () {
|
60 | console.log('Sample app started at localhost:3000');
|
61 | });
|
62 |
|
63 |
|