Skip to content

Commit 94ec7d0

Browse files
committed
Use Environment variable to determine production environment
1 parent 581bb9d commit 94ec7d0

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

server/server.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ app.use(loopback.compress());
3535
// -- Add your pre-processing middleware here --
3636

3737
var ds = loopback.createDataSource({
38-
connector: require('loopback-component-storage'),
39-
provider: 'filesystem',
40-
root: path.join(__dirname, '../', 'storage')
38+
connector: require('loopback-component-storage'),
39+
provider: 'filesystem',
40+
root: path.join(__dirname, '../', 'storage')
4141
});
4242
var container = ds.createModel('container');
4343

@@ -70,7 +70,7 @@ app.use(loopback.session({
7070
var config = {};
7171
try {
7272
config = require('../providers.json');
73-
} catch(err) {
73+
} catch (err) {
7474
console.error('Please configure your passport strategy in `providers.json`.');
7575
console.error('Copy `providers.json.template` to `providers.json` and replace the clientID/clientSecret values with your own.');
7676
process.exit(1);
@@ -85,7 +85,7 @@ passportConfigurator.setupModels({
8585
userCredentialModel: app.models.userCredential
8686
});
8787
// Configure passport strategies for third party auth providers
88-
for(var s in config) {
88+
for (var s in config) {
8989
var c = config[s];
9090
c.session = c.session !== false;
9191
passportConfigurator.configureProvider(s, c);
@@ -117,21 +117,18 @@ app.get('/auth/logout', function (req, res, next) {
117117
// All static middleware should be registered at the end, as all requests
118118
// passing the static middleware are hitting the file system
119119
// Example:
120-
//app.use(loopback.static(path.resolve(__dirname, '../client/app')));
121120

122-
var dist = false;
121+
var staticPath = null;
123122

124-
var Static = null;
125-
126-
if (argv['dist'] === true) {
127-
Static = path.resolve(__dirname, '../dist/');
123+
if (process.env.NODE_ENV === 'production') {
124+
staticPath = path.resolve(__dirname, '../dist/');
128125
}
129126
else {
130-
Static = path.resolve(__dirname, '../client/app');
127+
staticPath = path.resolve(__dirname, '../client/app');
131128
}
132129

133-
console.log("Static", Static);
134-
app.use(loopback.static(Static));
130+
console.log("staticPath", staticPath);
131+
app.use(loopback.static(staticPath));
135132

136133
// Requests that get this far won't be handled
137134
// by any middleware. Convert them into a 404 error
@@ -141,9 +138,9 @@ app.use(loopback.urlNotFound());
141138
// The ultimate error handler.
142139
app.use(loopback.errorHandler());
143140

144-
app.start = function() {
141+
app.start = function () {
145142
// start the web server
146-
return app.listen(function() {
143+
return app.listen(function () {
147144
app.emit('started');
148145
console.log('Web server listening at: %s', app.get('url'));
149146
});

0 commit comments

Comments
 (0)