Skip to content

Commit

Permalink
use a cookie to determine development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
saharj committed May 4, 2016
1 parent 9d1bba6 commit 48a9525
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ opening the browser
DO_NOT_OPEN=true npm start
```

### Running in production mode

Pass `--production` flag to `npm start` to run in production mode
```shell
npm start --production

```

### Building
To build the project for production use, run:

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"devDependencies": {
"angular": "^1.5.2",
"angular-cookies": "^1.5.5",
"angular-json-schema-form": "^0.1.4",
"angular-marked": "^1.0.1",
"angular-mocks": "^1.5.2",
Expand Down
9 changes: 7 additions & 2 deletions scripts/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var angular = require('angular');

SwaggerEditor.config(function Router($compileProvider, $stateProvider,
$urlRouterProvider, $logProvider) {
$urlRouterProvider.otherwise('/');
Expand Down Expand Up @@ -27,8 +29,11 @@ SwaggerEditor.config(function Router($compileProvider, $stateProvider,
}
});

var $cookies = angular.injector([require('angular-cookies')]).get('$cookies');
var isDevelopment = Boolean($cookies.get('swagger-editor-development-mode'));

$compileProvider.aHrefSanitizationWhitelist('.');

$compileProvider.debugInfoEnabled(true);
$logProvider.debugEnabled(true);
$compileProvider.debugInfoEnabled(isDevelopment);
$logProvider.debugEnabled(isDevelopment);
});
7 changes: 6 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
var open = require('open');
var IP = '127.0.0.1';
var argv = require('minimist')(process.argv.slice(2));

/**
* Start the server with webpack config
Expand All @@ -20,7 +21,11 @@ function startServer(port, cb) {
var server = new WebpackDevServer(compiler, {
progress: true,
quiet: true,
publicPath: config.output.publicPath
publicPath: config.output.publicPath,
headers: {
'Set-Cookie':
'swagger-editor-development-mode:' + Boolean(argv.production) + ';'
}
});

server.listen(port, IP, cb);
Expand Down

0 comments on commit 48a9525

Please sign in to comment.