|
1 |
| -/** |
2 |
| - * app.js |
3 |
| - * |
4 |
| - * Use `app.js` to run your app without `sails lift`. |
5 |
| - * To start the server, run: `node app.js`. |
6 |
| - * |
7 |
| - * This is handy in situations where the sails CLI is not relevant or useful. |
8 |
| - * |
9 |
| - * For example: |
10 |
| - * => `node app.js` |
11 |
| - * => `forever start app.js` |
12 |
| - * => `node debug app.js` |
13 |
| - * => `modulus deploy` |
14 |
| - * => `heroku scale` |
15 |
| - * |
16 |
| - * |
17 |
| - * The same command-line arguments are supported, e.g.: |
18 |
| - * `node app.js --silent --port=80 --prod` |
19 |
| - */ |
| 1 | +var path = require('path'), |
| 2 | + hapi = require('hapi'), |
| 3 | + good = require('good'), |
| 4 | + server = new hapi.Server(3000), |
| 5 | + routes = require('./server/routes'), |
| 6 | + db = require('./server/services/db'); |
20 | 7 |
|
21 |
| -// Ensure a "sails" can be located: |
22 |
| -(function() { |
23 |
| - var sails; |
24 |
| - try { |
25 |
| - sails = require('sails'); |
26 |
| - } catch (e) { |
27 |
| - console.error('To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); |
28 |
| - console.error('To do that, run `npm install sails`'); |
29 |
| - console.error(''); |
30 |
| - console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); |
31 |
| - console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); |
32 |
| - console.error('but if it doesn\'t, the app will run with the global sails instead!'); |
33 |
| - return; |
34 |
| - } |
| 8 | +// Setup server |
| 9 | +routes.registerRoutes(server); |
| 10 | +server.views({ |
| 11 | + engines: { |
| 12 | + html: require('handlebars') |
| 13 | + }, |
| 14 | + path: path.join(__dirname, 'server/views') |
| 15 | +}); |
35 | 16 |
|
36 |
| - // Try to get `rc` dependency |
37 |
| - var rc; |
38 |
| - try { |
39 |
| - rc = require('rc'); |
40 |
| - } catch (e0) { |
41 |
| - try { |
42 |
| - rc = require('sails/node_modules/rc'); |
43 |
| - } catch (e1) { |
44 |
| - console.error('Could not find dependency: `rc`.'); |
45 |
| - console.error('Your `.sailsrc` file(s) will be ignored.'); |
46 |
| - console.error('To resolve this, run:'); |
47 |
| - console.error('npm install rc --save'); |
48 |
| - rc = function () { return {}; }; |
49 |
| - } |
50 |
| - } |
| 17 | +console.log('Attempting to connect to MongoDB via Mongoose...'); |
| 18 | +db.connect(function(valid) { |
| 19 | + if(valid) { |
| 20 | + console.log('Successfully connected to MongoDB via Mongoose!'); |
51 | 21 |
|
52 |
| - var db = require('./api/services/db'); |
53 |
| - sails.log.info('Attempting to connect to MongoDB via Mongoose...'); |
54 |
| - db.connect(function(valid) { |
55 |
| - if(valid) { |
56 |
| - sails.log.info('Successfully connected to MongoDB via Mongoose!'); |
| 22 | + // Application setup |
| 23 | + var argv = require('minimist')(process.argv.slice(2)); |
57 | 24 |
|
58 |
| - // Application setup |
59 |
| - var argv = require('minimist')(process.argv.slice(2)); |
| 25 | + if(argv['force-setup']) { |
| 26 | + require('shelljs/global'); |
| 27 | + console.log('--force-setup flag detected, dropping server-dash database and running setup script.'); |
| 28 | + exec('mongo server-dash --eval "db.dropDatabase()"'); |
| 29 | + } |
60 | 30 |
|
61 |
| - if(argv['force-setup']) { |
62 |
| - require('shelljs/global'); |
63 |
| - sails.log.info('--force-setup flag detected, dropping server-dash database and running setup script.'); |
64 |
| - exec('mongo server-dash --eval "db.dropDatabase()"'); |
65 |
| - } |
| 31 | + var setup = require('./setup/setup.js'); |
66 | 32 |
|
67 |
| - var setup = require('./setup/setup.js'); |
| 33 | + setup.userSetup(function() { |
| 34 | + setup.widgetSetup(function() { |
| 35 | + server.pack.register([good, require('hapi-auth-cookie')], function(err) { |
| 36 | + if(err) { |
| 37 | + throw err; // plugin failed |
| 38 | + } |
68 | 39 |
|
69 |
| - setup.userSetup(function() { |
70 |
| - setup.widgetSetup(function() { |
71 |
| - sails.lift(rc('sails')); |
| 40 | + server.auth.strategy('session', 'cookie', { |
| 41 | + password: 'Th!sAppR0cks!', // cookie secret |
| 42 | + cookie: '_serverDashAuth', // cookie name |
| 43 | + redirectTo: false, |
| 44 | + isSecure: false, |
| 45 | + ttl: 1000 * 60 * 60 * 24 |
| 46 | + }); |
| 47 | + |
| 48 | + server.start(function() { |
| 49 | + server.log('info', 'Server running at: ', server.info.uri); |
| 50 | + }); |
72 | 51 | });
|
73 | 52 | });
|
74 |
| - } else { |
75 |
| - sails.log.error('Error in Mongoose connection: ', error); |
76 |
| - } |
77 |
| - }); |
78 |
| -})(); |
| 53 | + }); |
| 54 | + } else { |
| 55 | + console.error('Error in Mongoose connection.'); |
| 56 | + } |
| 57 | +}); |
0 commit comments