Skip to content

Commit 1e95287

Browse files
committed
Added environment variables to README; added config/env/development.js.
1 parent b69b58b commit 1e95287

File tree

11 files changed

+93
-29
lines changed

11 files changed

+93
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ lib-cov
135135
.idea/*
136136
!.idea/runConfigurations/
137137
!.idea/codeStyles/
138+
!.idea/dictionaries/
138139

139140
# Elastic Beanstalk Files
140141
.elasticbeanstalk/*

.idea/dictionaries/neonexusdemortis.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is an opinionated base [Sails v1](https://sailsjs.com) application, using W
1515
## How to Use
1616
This repo is not installable via `npm`. Instead, Github provides a handy "Use this template" (green) button at the top of this page. That will create a special fork of this repo (so there is a single, init commit, instead of the commit history from this repo).
1717

18-
Scripts built into [`package.json`](package.json):
18+
### Scripts built into [`package.json`](package.json):
1919

2020
| Command | Description
2121
|---------------|-------------------
@@ -26,10 +26,22 @@ Scripts built into [`package.json`](package.json):
2626
|npm run build | Will run `npm run clean`, then will build production-ready files with Webpack in the `.tmp/public` folder.
2727
|npm run build:dev | Same thing as `npm run build`, except that it will not optimize the files, retaining newlines and empty spaces.
2828
|npm run clean | Will basically delete everything in the `.tmp` folder.
29-
|npm run lines | Will count the lines of code in the project, minus `.gitignore`'d files, for funzies. There are currently about **6k** custom lines in this repo (views, controllers, helpers, hooks, etc).
29+
|npm run lines | Will count the lines of code in the project, minus `.gitignore`'d files, for funzies. There are currently about 6k custom lines in this repo (views, controllers, helpers, hooks, etc).
3030
|npm run test | Run [Mocha](https://mochajs.org/) tests. Everything starts in the [`test/hooks.js`](test/hooks.js) file.
3131
|npm run coverage | Runs [NYC](https://www.npmjs.com/package/nyc) coverage reporting of the Mocha tests, which generates HTML in `test/coverage`.
3232

33+
### Environment Variables used for remote servers:
34+
| Variable | Description
35+
|---------------|----------------------
36+
| ASSETS_URL | Webpack is configured to modify static asset URLs to point to a CDN, like CloudFront. MUST end with a slash " / ".
37+
| BASE_URL | The address of the Sails instance.
38+
| DB_HOST | The hostname of the datastore.
39+
| DB_USER | Username for the datastore.
40+
| DB_PASS | Password for the datastore.
41+
| DB_NAME | The name of the database inside the datastore.
42+
| DB_PORT | The port number for datastore.
43+
| DB_SSL | If the datastore requires SSL, set this to "true".
44+
3345
## Request Logging
3446
Automatic incoming request logging, is a 2 part process. First, the [`request-logger` hook](api/hooks/request-logger.js) gathers info from the request, and creates a new [`RequestLog` record](api/models/RequestLog.js), making sure to mask anything that may be sensitive, such as passwords. Then, a custom response gathers information from the response, again, scrubbing sensitive data (using the [customToJSON](https://sailsjs.com/documentation/concepts/models-and-orm/model-settings?identity=#customtojson) feature of Sails models) to prevent leaking of password hashes, or anything else that should never be publicly accessible. The [`keepModelsSafe` helper](api/helpers/keep-models-safe.js) and the custom responses (such as [ok](api/responses/ok.js) or [serverError](api/responses/serverError.js)) are responsible for the final leg of request logs.
3547

@@ -71,6 +83,7 @@ module.exports.bootstrap = function(next) {
7183
+ [Sails Professional / Enterprise Options](https://sailsjs.com/enterprise)
7284
+ [`react-bootstrap` Documentation](https://react-bootstrap.netlify.app/)
7385
+ [Webpack Documentation](https://webpack.js.org/)
86+
+ [Simple data fixtures for testing Sails.js](https://www.npmjs.com/package/fixted)
7487

7588

7689
### Version info

api/controllers/admin/create-user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
friendlyName: 'Create Account',
2+
friendlyName: 'Create User',
33

4-
description: 'Create a new account.',
4+
description: 'Create a new user.',
55

66
inputs: {
77
firstName: {
@@ -51,7 +51,7 @@ module.exports = {
5151
return exits.badRequest(isPasswordValid);
5252
}
5353

54-
User.create({
54+
sails.models.user.create({
5555
id: 'c', // required, but auto-generated
5656
firstName: inputs.firstName,
5757
lastName: inputs.lastName,

assets/src/Admin/SidebarNav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SidebarNav extends React.Component {
3030
<div id="sidebar-nav" className="hidden-sm">
3131
<div className="logo">
3232
<Link to="/admin/dashboard">
33-
<img src={logo} />
33+
<img src={logo} alt="Logo" />
3434
</Link>
3535
</div>
3636
<div className="sidebar-wrapper">

assets/src/common/api.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class api {
44
constructor(baseUrl) {
55
this.baseUrl = baseUrl || process.env.baseUrl;
66
this.request = request.agent(); // cookie handler
7-
this.isActive = false;
87
this.queue = [];
98
}
109

config/datastores.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports.datastores = {
5454
host: process.env.DB_HOST || 'localhost',
5555
user: process.env.DB_USER || 'root',
5656
password: process.env.DB_PASS || 'mypass',
57-
database: process.env.DB || 'myapp',
57+
database: process.env.DB_NAME || 'myapp',
5858
port: process.env.DB_PORT || 3306,
5959
charset: 'utf8mb4',
6060
collation: 'utf8mb4_general_ci',

config/env/development.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Development environment settings
3+
*
4+
* This file can include shared settings for a development team,
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+
logSensitiveData: false, // never log sensitive data in remote development database
15+
16+
baseUrl: process.env.BASE_URL || 'https://my-api.app',
17+
assetsUrl: process.env.ASSETS_URL || '', // Something like: https://my-cdn.app/ must end with /
18+
19+
/***************************************************************************
20+
* Set the default database connection for models in the development *
21+
* environment (see config/datastores.js and config/models.js ) *
22+
***************************************************************************/
23+
24+
datastores: {
25+
host: process.env.DB_HOST || 'localhost',
26+
user: process.env.DB_USER || 'root',
27+
password: process.env.DB_PASS || 'mypass',
28+
database: process.env.DB_NAME || 'myapp',
29+
port: process.env.DB_PORT || 3306,
30+
ssl: (process.env.DB_SSL === 'true')
31+
},
32+
33+
models: {
34+
migrate: 'safe' // This is set as safe, so remote development machines are behaving like remote production machines. Use local.js to override.
35+
},
36+
37+
blueprints: {
38+
shortcuts: false // don't accidentally expose API routes in a remote environment
39+
}
40+
};

config/env/production.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = {
2323

2424
logSensitiveData: false, // never log sensitive data in production database
2525

26-
baseUrl: 'https://myapi.app',
27-
assetsUrl: 'https://my-cdn.app/', // must end with /
26+
baseUrl: process.env.BASE_URL || 'https://my-api.app',
27+
assetsUrl: process.env.ASSETS_URL || '', // Something like: https://my-cdn.app/ must end with /
2828

2929
/**************************************************************************
3030
* *
@@ -50,15 +50,12 @@ module.exports = {
5050
* *
5151
***************************************************************************/
5252
default: {
53-
host: process.env.RDS_HOSTNAME || 'localhost',
54-
user: process.env.RDS_USERNAME || 'produser',
55-
password: process.env.RDS_PASSWORD || 'myprodpassword',
56-
database: process.env.RDS_DB_NAME || 'proddatabase',
57-
port: process.env.RDS_PORT || 3306,
58-
charset: 'utf8mb4',
59-
collation: 'utf8mb4_general_ci',
60-
timezone: 'UTC',
61-
ssl: (process.env.RDS_SSL === 'true')
53+
host: process.env.DB_HOSTNAME || 'localhost',
54+
user: process.env.DB_USERNAME || 'produser',
55+
password: process.env.DB_PASSWORD || 'myprodpassword',
56+
database: process.env.DB_NAME || 'proddatabase',
57+
port: process.env.DB_PORT || 3306,
58+
ssl: (process.env.DB_SSL === 'true')
6259
}
6360
},
6461

@@ -214,11 +211,12 @@ module.exports = {
214211
// https://jsfiddle.net/fsbd3ey5/1/
215212
secret: process.env.SESSION_SECRET, // DO NOT STORE THIS IN SOURCE CONTROL!!!
216213

217-
host: process.env.RDS_HOSTNAME,
218-
port: process.env.RDS_PORT,
219-
user: process.env.RDS_USERNAME,
220-
password: process.env.RDS_PASSWORD,
221-
database: process.env.RDS_DB_NAME,
214+
host: process.env.DB_HOSTNAME || 'localhost',
215+
user: process.env.DB_USERNAME || 'produser',
216+
password: process.env.DB_PASSWORD || 'myprodpassword',
217+
database: process.env.DB_NAME || 'proddatabase',
218+
port: process.env.DB_PORT || 3306,
219+
ssl: (process.env.DB_SSL === 'true')
222220
},
223221

224222

test/hooks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ exports.mochaHooks = {
5454
sails: true,
5555
_,
5656
async: false,
57-
models: true
57+
models: false
5858
}
5959
}), function(err, sailsApp){
6060
if (err) {
@@ -64,7 +64,6 @@ exports.mochaHooks = {
6464
// sanity checks
6565
should.exist(sails);
6666
sails.should.have.property('models');
67-
sails.models.should.have.property('requestlog');
6867

6968
fs.readdir( path.join(__dirname, '../api/models'), (error, files) => {
7069
should.not.exist(error);

test/integration/models/User.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
const userFixtures = require('../../fixtures/User.js');
22

3-
describe('User', function() {
3+
describe('User Model', function() {
4+
before(function() {
5+
// sanity checks
6+
should.exist(sails);
7+
sails.models.should.have.property('user');
8+
});
9+
410
describe('.find()', function() {
511
it('should return all user fixtures', async function() {
6-
const foundUsers = await User.find({});
12+
const foundUsers = await sails.models.user.find({});
713
foundUsers.should.be.an('array');
814
foundUsers.should.have.lengthOf(userFixtures.length);
915

@@ -17,7 +23,7 @@ describe('User', function() {
1723

1824
describe('.toJSON()', function() {
1925
it('should not expose sensitive information to the outside world', async function() {
20-
const foundUsers = await User.find();
26+
const foundUsers = await sails.models.user.find({});
2127
foundUsers.should.be.an('array');
2228

2329
// make sure password is never exposed to the outside world

0 commit comments

Comments
 (0)