13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/assets/robots.txt:
--------------------------------------------------------------------------------
1 | # The robots.txt file is used to control how search engines index your live URLs.
2 | # See http://www.robotstxt.org/wc/norobots.html for more information.
3 |
4 |
5 |
6 | # To prevent search engines from seeing the site altogether, uncomment the next two lines:
7 | # User-Agent: *
8 | # Disallow: /
9 |
--------------------------------------------------------------------------------
/components/front/layout.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | import React from 'react'
4 | import Nav from './partials/nav'
5 |
6 | export default class {
7 | render() {
8 | return (
9 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | );
54 |
--------------------------------------------------------------------------------
/config/log.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Built-in Log Configuration
3 | * (sails.config.log)
4 | *
5 | * Configure the log level for your app, as well as the transport
6 | * (Underneath the covers, Sails uses Winston for logging, which
7 | * allows for some pretty neat custom transports/adapters for log messages)
8 | *
9 | * For more information on the Sails logger, check out:
10 | * http://sailsjs.org/#/documentation/concepts/Logging
11 | */
12 |
13 | module.exports.log = {
14 |
15 | /***************************************************************************
16 | * *
17 | * Valid `level` configs: i.e. the minimum log level to capture with *
18 | * sails.log.*() *
19 | * *
20 | * The order of precedence for log levels from lowest to highest is: *
21 | * silly, verbose, info, debug, warn, error *
22 | * *
23 | * You may also set the level to "silent" to suppress all logs. *
24 | * *
25 | ***************************************************************************/
26 |
27 | // level: 'info'
28 |
29 | };
30 |
--------------------------------------------------------------------------------
/api/responses/ok.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 200 (OK) Response
3 | *
4 | * Usage:
5 | * return res.ok();
6 | * return res.ok(data);
7 | * return res.ok(data, 'auth/login');
8 | *
9 | * @param {Object} data
10 | * @param {String|Object} options
11 | * - pass string to render specified view
12 | */
13 |
14 | module.exports = function sendOK (data, options) {
15 |
16 | // Get access to `req`, `res`, & `sails`
17 | var req = this.req;
18 | var res = this.res;
19 | var sails = req._sails;
20 |
21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response');
22 |
23 | // Set status code
24 | res.status(200);
25 |
26 | // If appropriate, serve data as JSON(P)
27 | if (req.wantsJSON) {
28 | return res.jsonx(data);
29 | }
30 |
31 | // If second argument is a string, we take that to mean it refers to a view.
32 | // If it was omitted, use an empty object (`{}`)
33 | options = (typeof options === 'string') ? { view: options } : options || {};
34 |
35 | // If a view was provided in options, serve it.
36 | // Otherwise try to guess an appropriate view, or if that doesn't
37 | // work, just send JSON.
38 | if (options.view) {
39 | return res.view(options.view, { data: data });
40 | }
41 |
42 | // If no second argument provided, try to serve the implied view,
43 | // but fall back to sending JSON(P) if no view can be inferred.
44 | else return res.guessView({ data: data }, function couldNotGuessView () {
45 | return res.jsonx(data);
46 | });
47 |
48 | };
49 |
--------------------------------------------------------------------------------
/tasks/config/jst.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Precompiles Underscore templates to a `.jst` file.
3 | *
4 | * ---------------------------------------------------------------
5 | *
6 | * (i.e. basically it takes HTML files and turns them into tiny little
7 | * javascript functions that you pass data to and return HTML. This can
8 | * speed up template rendering on the client, and reduce bandwidth usage.)
9 | *
10 | * For usage docs see:
11 | * https://github.com/gruntjs/grunt-contrib-jst
12 | *
13 | */
14 |
15 | module.exports = function(grunt) {
16 |
17 | var templateFilesToInject = [
18 | 'templates/**/*.html'
19 | ];
20 |
21 | grunt.config.set('jst', {
22 | dev: {
23 |
24 | // To use other sorts of templates, specify a regexp like the example below:
25 | // options: {
26 | // templateSettings: {
27 | // interpolate: /\{\{(.+?)\}\}/g
28 | // }
29 | // },
30 |
31 | // Note that the interpolate setting above is simply an example of overwriting lodash's
32 | // default interpolation. If you want to parse templates with the default _.template behavior
33 | // (i.e. using ), there's no need to overwrite `templateSettings.interpolate`.
34 |
35 |
36 | files: {
37 | // e.g.
38 | // 'relative/path/from/gruntfile/to/compiled/template/destination' : ['relative/path/to/sourcefiles/**/*.html']
39 | '.tmp/public/jst.js': require('../pipeline').templateFilesToInject
40 | }
41 | }
42 | });
43 |
44 | grunt.loadNpmTasks('grunt-contrib-jst');
45 | };
46 |
--------------------------------------------------------------------------------
/components/admin/nav.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | import React from 'react'
4 | import {Link} from 'react-router'
5 |
6 | export default class {
7 | render() {
8 | let identities = this.props.identities;
9 | return (
10 |
42 | )
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/config/env/production.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Production environment settings
3 | *
4 | * This file can include shared settings for a production environment,
5 | * such as API keys or remote database passwords. If you're using
6 | * a version control solution for your Sails app, this file will
7 | * be committed to your repository unless you add it to your .gitignore
8 | * file. If your repository will be publicly viewable, don't add
9 | * any private information to this file!
10 | *
11 | */
12 |
13 | module.exports = {
14 |
15 | /***************************************************************************
16 | * Set the default database connection for models in the production *
17 | * environment (see config/connections.js and config/models.js ) *
18 | ***************************************************************************/
19 |
20 | // models: {
21 | // connection: 'someMysqlServer'
22 | // },
23 |
24 | /***************************************************************************
25 | * Set the port in the production environment to 80 *
26 | ***************************************************************************/
27 |
28 | // port: 80,
29 |
30 | /***************************************************************************
31 | * Set the log level in production environment to "silent" *
32 | ***************************************************************************/
33 |
34 | // log: {
35 | // level: "silent"
36 | // }
37 |
38 | };
39 |
--------------------------------------------------------------------------------
/config/models.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Default model configuration
3 | * (sails.config.models)
4 | *
5 | * Unless you override them, the following properties will be included
6 | * in each of your models.
7 | *
8 | * For more info on Sails models, see:
9 | * http://sailsjs.org/#/documentation/concepts/ORM
10 | */
11 |
12 | module.exports.models = {
13 |
14 | /***************************************************************************
15 | * *
16 | * Your app's default connection. i.e. the name of one of your app's *
17 | * connections (see `config/connections.js`) *
18 | * *
19 | ***************************************************************************/
20 | // connection: 'localDiskDb',
21 |
22 | /***************************************************************************
23 | * *
24 | * How and whether Sails will attempt to automatically rebuild the *
25 | * tables/collections/etc. in your schema. *
26 | * *
27 | * See http://sailsjs.org/#/documentation/concepts/ORM/model-settings.html *
28 | * *
29 | ***************************************************************************/
30 | // migrate: 'alter'
31 | migrate: 'safe'
32 | };
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sails-isomorphic-react-admin-example",
3 | "private": true,
4 | "version": "0.0.0",
5 | "description": "a Sails application with isomorphic and a separate administration(automatic & extendable)",
6 | "keywords": [
7 | "sails",
8 | "react",
9 | "isomorphic",
10 | "administration",
11 | "automatic",
12 | "admin"
13 | ],
14 | "dependencies": {
15 | "auto-admin": "^0.2.8",
16 | "babelify": "^6.3.0",
17 | "ejs": "~0.8.4",
18 | "grunt": "0.4.2",
19 | "grunt-browserify": "^4.0.1",
20 | "grunt-contrib-clean": "~0.5.0",
21 | "grunt-contrib-coffee": "~0.10.1",
22 | "grunt-contrib-concat": "~0.3.0",
23 | "grunt-contrib-copy": "~0.5.0",
24 | "grunt-contrib-cssmin": "~0.9.0",
25 | "grunt-contrib-jst": "~0.6.0",
26 | "grunt-contrib-less": "0.11.1",
27 | "grunt-contrib-uglify": "~0.4.0",
28 | "grunt-contrib-watch": "~0.5.3",
29 | "grunt-react": "^0.12.2",
30 | "grunt-sails-linker": "~0.9.5",
31 | "grunt-sync": "~0.0.4",
32 | "include-all": "~0.1.3",
33 | "newforms": "^0.12.1",
34 | "newforms-bootstrap": "^2.0.0",
35 | "rc": "~0.5.0",
36 | "react": "^0.13.3",
37 | "react-router": "^0.13.3",
38 | "sails": "~0.11.0",
39 | "sails-disk": "~0.10.0",
40 | "sails-hook-babel": "^5.0.1"
41 | },
42 | "scripts": {
43 | "start": "node app.js",
44 | "debug": "node debug app.js"
45 | },
46 | "main": "app.js",
47 | "repository": {
48 | "type": "git",
49 | "url": "git://github.com/wi2/sails-isomorphic-react-admin-example.git"
50 | },
51 | "author": "Mike WI2",
52 | "license": "MIT"
53 | }
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sails Isomorphic React with Admin Example
2 |
3 | a [Sails](http://sailsjs.org) application with
4 | - All the interface are automatically created
5 | - The forms are automatically generated depending on model's attributes
6 | - separate compiling assets for backoffice and frontoffice
7 | - react isomorphic render
8 | - simple administration automatic(model) and extendable
9 | - ES6
10 |
11 | with
12 | - [sails](http://sailsjs.org)
13 | - [react](https://github.com/facebook/react)
14 | - [react-router](https://github.com/rackt/react-router)
15 | - [auto-admin](https://github.com/wi2/auto-admin)
16 | - [newforms](https://github.com/insin/newforms)
17 | - [newforms-bootstrap](https://github.com/insin/newforms-bootstrap)
18 | - [browserify](https://github.com/substack/node-browserify)
19 | - [sails-hook-babel](https://github.com/artificialio/sails-hook-babel)
20 |
21 |
22 |
23 | ## Quick start :
24 | ```sh
25 | npm install
26 |
27 | npm install -g browserify
28 |
29 | browserify -r react -r react-router -r newforms -r newforms-bootstrap -r auto-admin -r rc-pagination > assets/js/admin/dependencies/build.js
30 |
31 | browserify -r react -r react-router > assets/js/front/dependencies/build.js
32 |
33 |
34 | sails generate api post
35 | sails generate api comment
36 | ```
37 |
38 | ```js
39 |
40 | //api/models/Post.js
41 | module.exports = {
42 | attributes: {
43 | title: 'string',
44 | content: 'text',
45 | comments: {
46 | collection:'comment',
47 | via: 'post'
48 | }
49 | }
50 | };
51 |
52 | //api/models/Comment.js
53 | module.exports = {
54 | attributes: {
55 | name: 'string',
56 | message: 'text',
57 | post: {
58 | model: 'post'
59 | }
60 | }
61 | };
62 |
63 | ```
64 |
65 |
66 | ```sh
67 | sails lift
68 | ```
69 |
70 | and go to http://localhost:1337/admin to see auto generate admin
71 |
72 | ## customize form with [newforms-bootstrap](https://github.com/insin/newforms-bootstrap)
73 | see components/admin/forms.js and update this.
74 |
75 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
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 | */
20 |
21 | // Ensure we're in the project directory, so relative paths work as expected
22 | // no matter where we actually lift from.
23 | process.chdir(__dirname);
24 |
25 | // Ensure a "sails" can be located:
26 | (function() {
27 | var sails;
28 | try {
29 | sails = require('sails');
30 | } catch (e) {
31 | 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.');
32 | console.error('To do that, run `npm install sails`');
33 | console.error('');
34 | console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.');
35 | console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,');
36 | console.error('but if it doesn\'t, the app will run with the global sails instead!');
37 | return;
38 | }
39 |
40 | // Try to get `rc` dependency
41 | var rc;
42 | try {
43 | rc = require('rc');
44 | } catch (e0) {
45 | try {
46 | rc = require('sails/node_modules/rc');
47 | } catch (e1) {
48 | console.error('Could not find dependency: `rc`.');
49 | console.error('Your `.sailsrc` file(s) will be ignored.');
50 | console.error('To resolve this, run:');
51 | console.error('npm install rc --save');
52 | rc = function () { return {}; };
53 | }
54 | }
55 |
56 |
57 | // Start server
58 | sails.lift(rc('sails'));
59 | })();
60 |
--------------------------------------------------------------------------------
/api/responses/badRequest.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 400 (Bad Request) Handler
3 | *
4 | * Usage:
5 | * return res.badRequest();
6 | * return res.badRequest(data);
7 | * return res.badRequest(data, 'some/specific/badRequest/view');
8 | *
9 | * e.g.:
10 | * ```
11 | * return res.badRequest(
12 | * 'Please choose a valid `password` (6-12 characters)',
13 | * 'trial/signup'
14 | * );
15 | * ```
16 | */
17 |
18 | module.exports = function badRequest(data, options) {
19 |
20 | // Get access to `req`, `res`, & `sails`
21 | var req = this.req;
22 | var res = this.res;
23 | var sails = req._sails;
24 |
25 | // Set status code
26 | res.status(400);
27 |
28 | // Log error to console
29 | if (data !== undefined) {
30 | sails.log.verbose('Sending 400 ("Bad Request") response: \n',data);
31 | }
32 | else sails.log.verbose('Sending 400 ("Bad Request") response');
33 |
34 | // Only include errors in response if application environment
35 | // is not set to 'production'. In production, we shouldn't
36 | // send back any identifying information about errors.
37 | if (sails.config.environment === 'production') {
38 | data = undefined;
39 | }
40 |
41 | // If the user-agent wants JSON, always respond with JSON
42 | if (req.wantsJSON) {
43 | return res.jsonx(data);
44 | }
45 |
46 | // If second argument is a string, we take that to mean it refers to a view.
47 | // If it was omitted, use an empty object (`{}`)
48 | options = (typeof options === 'string') ? { view: options } : options || {};
49 |
50 | // If a view was provided in options, serve it.
51 | // Otherwise try to guess an appropriate view, or if that doesn't
52 | // work, just send JSON.
53 | if (options.view) {
54 | return res.view(options.view, { data: data });
55 | }
56 |
57 | // If no second argument provided, try to serve the implied view,
58 | // but fall back to sending JSON(P) if no view can be inferred.
59 | else return res.guessView({ data: data }, function couldNotGuessView () {
60 | return res.jsonx(data);
61 | });
62 |
63 | };
64 |
65 |
--------------------------------------------------------------------------------
/config/policies.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Policy Mappings
3 | * (sails.config.policies)
4 | *
5 | * Policies are simple functions which run **before** your controllers.
6 | * You can apply one or more policies to a given controller, or protect
7 | * its actions individually.
8 | *
9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed
10 | * below by its filename, minus the extension, (e.g. "authenticated")
11 | *
12 | * For more information on how policies work, see:
13 | * http://sailsjs.org/#/documentation/concepts/Policies
14 | *
15 | * For more information on configuring policies, check out:
16 | * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.policies.html
17 | */
18 |
19 |
20 | module.exports.policies = {
21 |
22 | /***************************************************************************
23 | * *
24 | * Default policy for all controllers and actions (`true` allows public *
25 | * access) *
26 | * *
27 | ***************************************************************************/
28 |
29 | // '*': true,
30 |
31 | /***************************************************************************
32 | * *
33 | * Here's an example of mapping some policies to run before a controller *
34 | * and its actions *
35 | * *
36 | ***************************************************************************/
37 | // RabbitController: {
38 |
39 | // Apply the `false` policy as the default for all of RabbitController's actions
40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits)
41 | // '*': false,
42 |
43 | // For the action `nurture`, apply the 'isRabbitMother' policy
44 | // (this overrides `false` above)
45 | // nurture : 'isRabbitMother',
46 |
47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies
48 | // before letting any users feed our rabbits
49 | // feed : ['isNiceToAnimals', 'hasRabbitFood']
50 | // }
51 | };
52 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Gruntfile
3 | *
4 | * This Node script is executed when you run `grunt` or `sails lift`.
5 | * It's purpose is to load the Grunt tasks in your project's `tasks`
6 | * folder, and allow you to add and remove tasks as you see fit.
7 | * For more information on how this works, check out the `README.md`
8 | * file that was generated in your `tasks` folder.
9 | *
10 | * WARNING:
11 | * Unless you know what you're doing, you shouldn't change this file.
12 | * Check out the `tasks` directory instead.
13 | */
14 |
15 | module.exports = function(grunt) {
16 |
17 |
18 | // Load the include-all library in order to require all of our grunt
19 | // configurations and task registrations dynamically.
20 | var includeAll;
21 | try {
22 | includeAll = require('include-all');
23 | } catch (e0) {
24 | try {
25 | includeAll = require('sails/node_modules/include-all');
26 | }
27 | catch(e1) {
28 | console.error('Could not find `include-all` module.');
29 | console.error('Skipping grunt tasks...');
30 | console.error('To fix this, please run:');
31 | console.error('npm install include-all --save`');
32 | console.error();
33 |
34 | grunt.registerTask('default', []);
35 | return;
36 | }
37 | }
38 |
39 |
40 | /**
41 | * Loads Grunt configuration modules from the specified
42 | * relative path. These modules should export a function
43 | * that, when run, should either load/configure or register
44 | * a Grunt task.
45 | */
46 | function loadTasks(relPath) {
47 | return includeAll({
48 | dirname: require('path').resolve(__dirname, relPath),
49 | filter: /(.+)\.js$/
50 | }) || {};
51 | }
52 |
53 | /**
54 | * Invokes the function from a Grunt configuration module with
55 | * a single argument - the `grunt` object.
56 | */
57 | function invokeConfigFn(tasks) {
58 | for (var taskName in tasks) {
59 | if (tasks.hasOwnProperty(taskName)) {
60 | tasks[taskName](grunt);
61 | }
62 | }
63 | }
64 |
65 |
66 |
67 |
68 | // Load task functions
69 | var taskConfigurations = loadTasks('./tasks/config'),
70 | registerDefinitions = loadTasks('./tasks/register');
71 |
72 | // (ensure that a default task exists)
73 | if (!registerDefinitions.default) {
74 | registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
75 | }
76 |
77 | // Run task functions to configure Grunt.
78 | invokeConfigFn(taskConfigurations);
79 | invokeConfigFn(registerDefinitions);
80 |
81 | };
82 |
--------------------------------------------------------------------------------
/api/services/getFormDefinition.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | module.exports = function(def) {
4 | var definition = sails.models[def].definition;
5 | //Promise
6 | return new Promise( (resolve, reject) => {
7 | Promise.all(Object.keys(definition).map( assoc => { return prepare(def, definition[assoc], assoc); }) )
8 | .then( results => { resolve(results); } )
9 | .catch( err => { reject(err); } )
10 | });
11 | };
12 |
13 | function prepare(def, data, attr) {
14 | var validator = sails.models[def]._validator.validations[attr]
15 | , res = new Object(_.clone(validator));
16 |
17 | res.label = attr;
18 | res.input = data.type;
19 | switch(data.type) {
20 | case 'array': res.input = 'checkbox'; break;
21 | case 'json': res.input = 'text'; break;
22 | }
23 | //don't use for
26 | *
27 | * or (b) For AJAX/Socket-heavy and/or single-page apps:
28 | * Sending a GET request to the `/csrfToken` route, where it will be returned
29 | * as JSON, e.g.:
30 | * { _csrf: 'ajg4JD(JGdajhLJALHDa' }
31 | *
32 | *
33 | * Enabling this option requires managing the token in your front-end app.
34 | * For traditional web apps, it's as easy as passing the data from a view into a form action.
35 | * In AJAX/Socket-heavy apps, just send a GET request to the /csrfToken route to get a valid token.
36 | *
37 | * For more information on CSRF, check out:
38 | * http://en.wikipedia.org/wiki/Cross-site_request_forgery
39 | *
40 | * For more information on this configuration file, including info on CSRF + CORS, see:
41 | * http://beta.sailsjs.org/#/documentation/reference/sails.config/sails.config.csrf.html
42 | *
43 | */
44 |
45 | /****************************************************************************
46 | * *
47 | * Enabled CSRF protection for your site? *
48 | * *
49 | ****************************************************************************/
50 |
51 | // module.exports.csrf = false;
52 |
53 | /****************************************************************************
54 | * *
55 | * You may also specify more fine-grained settings for CSRF, including the *
56 | * domains which are allowed to request the CSRF token via AJAX. These *
57 | * settings override the general CORS settings in your config/cors.js file. *
58 | * *
59 | ****************************************************************************/
60 |
61 | // module.exports.csrf = {
62 | // grantTokenViaAjax: true,
63 | // origin: ''
64 | // }
65 |
--------------------------------------------------------------------------------
/tasks/README.md:
--------------------------------------------------------------------------------
1 | # About the `tasks` folder
2 |
3 | The `tasks` directory is a suite of Grunt tasks and their configurations, bundled for your convenience. The Grunt integration is mainly useful for bundling front-end assets, (like stylesheets, scripts, & markup templates) but it can also be used to run all kinds of development tasks, from browserify compilation to database migrations.
4 |
5 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, read on!
6 |
7 |
8 | ### How does this work?
9 |
10 | The asset pipeline bundled in Sails is a set of Grunt tasks configured with conventional defaults designed to make your project more consistent and productive.
11 |
12 | The entire front-end asset workflow in Sails is completely customizable-- while it provides some suggestions out of the box, Sails makes no pretense that it can anticipate all of the needs you'll encounter building the browser-based/front-end portion of your application. Who's to say you're even building an app for a browser?
13 |
14 |
15 |
16 | ### What tasks does Sails run automatically?
17 |
18 | Sails runs some of these tasks (the ones in the `tasks/register` folder) automatically when you run certain commands.
19 |
20 | ###### `sails lift`
21 |
22 | Runs the `default` task (`tasks/register/default.js`).
23 |
24 | ###### `sails lift --prod`
25 |
26 | Runs the `prod` task (`tasks/register/prod.js`).
27 |
28 | ###### `sails www`
29 |
30 | Runs the `build` task (`tasks/register/build.js`).
31 |
32 | ###### `sails www --prod` (production)
33 |
34 | Runs the `buildProd` task (`tasks/register/buildProd.js`).
35 |
36 |
37 | ### Can I customize this for SASS, Angular, client-side Jade templates, etc?
38 |
39 | You can modify, omit, or replace any of these Grunt tasks to fit your requirements. You can also add your own Grunt tasks- just add a `someTask.js` file in the `grunt/config` directory to configure the new task, then register it with the appropriate parent task(s) (see files in `grunt/register/*.js`).
40 |
41 |
42 | ### Do I have to use Grunt?
43 |
44 | Nope! To disable Grunt integration in Sails, just delete your Gruntfile or disable the Grunt hook.
45 |
46 |
47 | ### What if I'm not building a web frontend?
48 |
49 | That's ok! A core tenant of Sails is client-agnosticism-- it's especially designed for building APIs used by all sorts of clients; native Android/iOS/Cordova, serverside SDKs, etc.
50 |
51 | You can completely disable Grunt by following the instructions above.
52 |
53 | If you still want to use Grunt for other purposes, but don't want any of the default web front-end stuff, just delete your project's `assets` folder and remove the front-end oriented tasks from the `grunt/register` and `grunt/config` folders. You can also run `sails new myCoolApi --no-frontend` to omit the `assets` folder and front-end-oriented Grunt tasks for future projects. You can also replace your `sails-generate-frontend` module with alternative community generators, or create your own. This allows `sails new` to create the boilerplate for native iOS apps, Android apps, Cordova apps, SteroidsJS apps, etc.
54 |
55 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################
2 | ############### .gitignore ##################
3 | ################################################
4 | #
5 | # This file is only relevant if you are using git.
6 | #
7 | # Files which match the splat patterns below will
8 | # be ignored by git. This keeps random crap and
9 | # and sensitive credentials from being uploaded to
10 | # your repository. It allows you to configure your
11 | # app for your machine without accidentally
12 | # committing settings which will smash the local
13 | # settings of other developers on your team.
14 | #
15 | # Some reasonable defaults are included below,
16 | # but, of course, you should modify/extend/prune
17 | # to fit your needs!
18 | ################################################
19 |
20 |
21 |
22 |
23 | ################################################
24 | # Local Configuration
25 | #
26 | # Explicitly ignore files which contain:
27 | #
28 | # 1. Sensitive information you'd rather not push to
29 | # your git repository.
30 | # e.g., your personal API keys or passwords.
31 | #
32 | # 2. Environment-specific configuration
33 | # Basically, anything that would be annoying
34 | # to have to change every time you do a
35 | # `git pull`
36 | # e.g., your local development database, or
37 | # the S3 bucket you're using for file uploads
38 | # development.
39 | #
40 | ################################################
41 |
42 | config/local.js
43 |
44 |
45 |
46 |
47 |
48 | ################################################
49 | # Dependencies
50 | #
51 | # When releasing a production app, you may
52 | # consider including your node_modules and
53 | # bower_components directory in your git repo,
54 | # but during development, its best to exclude it,
55 | # since different developers may be working on
56 | # different kernels, where dependencies would
57 | # need to be recompiled anyway.
58 | #
59 | # More on that here about node_modules dir:
60 | # http://www.futurealoof.com/posts/nodemodules-in-git.html
61 | # (credit Mikeal Rogers, @mikeal)
62 | #
63 | # About bower_components dir, you can see this:
64 | # http://addyosmani.com/blog/checking-in-front-end-dependencies/
65 | # (credit Addy Osmani, @addyosmani)
66 | #
67 | ################################################
68 |
69 | node_modules
70 | bower_components
71 |
72 |
73 |
74 |
75 | ################################################
76 | # Sails.js / Waterline / Grunt
77 | #
78 | # Files generated by Sails and Grunt, or related
79 | # tasks and adapters.
80 | ################################################
81 | .tmp
82 | dump.rdb
83 |
84 |
85 |
86 |
87 |
88 | ################################################
89 | # Node.js / NPM
90 | #
91 | # Common files generated by Node, NPM, and the
92 | # related ecosystem.
93 | ################################################
94 | lib-cov
95 | *.seed
96 | *.log
97 | *.out
98 | *.pid
99 | npm-debug.log
100 |
101 |
102 |
103 |
104 |
105 | ################################################
106 | # Miscellaneous
107 | #
108 | # Common files generated by text editors,
109 | # operating systems, file systems, etc.
110 | ################################################
111 |
112 | *~
113 | *#
114 | .DS_STORE
115 | .netbeans
116 | nbproject
117 | .idea
118 | .node_history
119 |
--------------------------------------------------------------------------------
/config/globals.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Global Variable Configuration
3 | * (sails.config.globals)
4 | *
5 | * Configure which global variables which will be exposed
6 | * automatically by Sails.
7 | *
8 | * For more information on configuration, check out:
9 | * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.globals.html
10 | */
11 | module.exports.globals = {
12 |
13 | /****************************************************************************
14 | * *
15 | * Expose the lodash installed in Sails core as a global variable. If this *
16 | * is disabled, like any other node module you can always run npm install *
17 | * lodash --save, then var _ = require('lodash') at the top of any file. *
18 | * *
19 | ****************************************************************************/
20 |
21 | // _: true,
22 |
23 | /****************************************************************************
24 | * *
25 | * Expose the async installed in Sails core as a global variable. If this is *
26 | * disabled, like any other node module you can always run npm install async *
27 | * --save, then var async = require('async') at the top of any file. *
28 | * *
29 | ****************************************************************************/
30 |
31 | // async: true,
32 |
33 | /****************************************************************************
34 | * *
35 | * Expose the sails instance representing your app. If this is disabled, you *
36 | * can still get access via req._sails. *
37 | * *
38 | ****************************************************************************/
39 |
40 | // sails: true,
41 |
42 | /****************************************************************************
43 | * *
44 | * Expose each of your app's services as global variables (using their *
45 | * "globalId"). E.g. a service defined in api/models/NaturalLanguage.js *
46 | * would have a globalId of NaturalLanguage by default. If this is disabled, *
47 | * you can still access your services via sails.services.* *
48 | * *
49 | ****************************************************************************/
50 |
51 | // services: true,
52 |
53 | /****************************************************************************
54 | * *
55 | * Expose each of your app's models as global variables (using their *
56 | * "globalId"). E.g. a model defined in api/models/User.js would have a *
57 | * globalId of User by default. If this is disabled, you can still access *
58 | * your models via sails.models.*. *
59 | * *
60 | ****************************************************************************/
61 |
62 | // models: true
63 | };
64 |
--------------------------------------------------------------------------------
/config/cors.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Cross-Origin Resource Sharing (CORS) Settings
3 | * (sails.config.cors)
4 | *
5 | * CORS is like a more modern version of JSONP-- it allows your server/API
6 | * to successfully respond to requests from client-side JavaScript code
7 | * running on some other domain (e.g. google.com)
8 | * Unlike JSONP, it works with POST, PUT, and DELETE requests
9 | *
10 | * For more information on CORS, check out:
11 | * http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
12 | *
13 | * Note that any of these settings (besides 'allRoutes') can be changed on a per-route basis
14 | * by adding a "cors" object to the route configuration:
15 | *
16 | * '/get foo': {
17 | * controller: 'foo',
18 | * action: 'bar',
19 | * cors: {
20 | * origin: 'http://foobar.com,https://owlhoot.com'
21 | * }
22 | * }
23 | *
24 | * For more information on this configuration file, see:
25 | * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.cors.html
26 | *
27 | */
28 |
29 | module.exports.cors = {
30 |
31 | /***************************************************************************
32 | * *
33 | * Allow CORS on all routes by default? If not, you must enable CORS on a *
34 | * per-route basis by either adding a "cors" configuration object to the *
35 | * route config, or setting "cors:true" in the route config to use the *
36 | * default settings below. *
37 | * *
38 | ***************************************************************************/
39 |
40 | // allRoutes: false,
41 |
42 | /***************************************************************************
43 | * *
44 | * Which domains which are allowed CORS access? This can be a *
45 | * comma-delimited list of hosts (beginning with http:// or https://) or *
46 | * "*" to allow all domains CORS access. *
47 | * *
48 | ***************************************************************************/
49 |
50 | // origin: '*',
51 |
52 | /***************************************************************************
53 | * *
54 | * Allow cookies to be shared for CORS requests? *
55 | * *
56 | ***************************************************************************/
57 |
58 | // credentials: true,
59 |
60 | /***************************************************************************
61 | * *
62 | * Which methods should be allowed for CORS requests? This is only used in *
63 | * response to preflight requests (see article linked above for more info) *
64 | * *
65 | ***************************************************************************/
66 |
67 | // methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
68 |
69 | /***************************************************************************
70 | * *
71 | * Which headers should be allowed for CORS requests? This is only used in *
72 | * response to preflight requests. *
73 | * *
74 | ***************************************************************************/
75 |
76 | // headers: 'content-type'
77 |
78 | };
79 |
--------------------------------------------------------------------------------
/views/403.ejs:
--------------------------------------------------------------------------------
1 |
2 |
36 |
37 |
38 | Forbidden
39 |
40 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | Forbidden
55 |
56 |
57 | <% if (typeof error !== 'undefined') { %>
58 | <%= error %>
59 | <% } else { %>
60 | You don't have permission to see the page you're trying to reach.
61 | <% } %>
62 |
Blueprints are just the beginning. You'll probably also want to learn how to customize your app's routes, set up security policies, configure your data sources, and build custom controller actions. For more help getting started, check out the links on this page.