Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 91 additions & 91 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<title>Swagger Editor</title>
<meta name="description" content="Swagger Editor">
<meta name="viewport" content="width=device-width">
<!-- build:css({.tmp,app}) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- build:css({.tmp,app}) ./styles/main.css -->
<link rel="stylesheet" href="./styles/main.css">
<!-- endbuild -->
<link rel="stylesheet" href="styles/branding.css">
<link rel="stylesheet" href="./styles/branding.css">
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:300,400,500,600' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
Expand All @@ -16,100 +16,100 @@
<body>
<div class="total-wrapper" ui-view></div>

<!-- build:js scripts/ace.js -->
<script src="bower_components/ace-builds/src-noconflict/ace.js"></script>
<script src="bower_components/ace-builds/src-noconflict/mode-yaml.js"></script>
<script src="bower_components/ace-builds/src-noconflict/ext-language_tools.js"></script>
<!-- build:js ./scripts/ace.js -->
<script src="./bower_components/ace-builds/src-noconflict/ace.js"></script>
<script src="./bower_components/ace-builds/src-noconflict/mode-yaml.js"></script>
<script src="./bower_components/ace-builds/src-noconflict/ext-language_tools.js"></script>
<!-- endbuild -->

<!-- build:js scripts/vendor.js -->
<script src="bower_components/yaml-js/yaml.js"></script>
<script src="bower_components/js-yaml/dist/js-yaml.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/json3/lib/json3.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/marked/lib/marked.js"></script>
<script src="bower_components/angular-marked/angular-marked.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/ngstorage/ngStorage.js"></script>
<script src="bower_components/angular-ui-ace/ui-ace.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="bower_components/json-formatter/dist/json-formatter.js"></script>
<script src="bower_components/angular-ui-layout/ui-layout.js"></script>
<script src="bower_components/json-schema-view/dist/json-schema-view.js"></script>
<script src="bower_components/tv4/tv4.js"></script>
<script src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script src="bower_components/swagger-converter/browser.js"></script>
<!-- build:js ./scripts/vendor.js -->
<script src="./bower_components/yaml-js/yaml.js"></script>
<script src="./bower_components/js-yaml/dist/js-yaml.js"></script>
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./bower_components/lodash/lodash.js"></script>
<script src="./bower_components/es5-shim/es5-shim.js"></script>
<script src="./bower_components/angular/angular.js"></script>
<script src="./bower_components/json3/lib/json3.js"></script>
<script src="./bower_components/angular-resource/angular-resource.js"></script>
<script src="./bower_components/marked/lib/marked.js"></script>
<script src="./bower_components/angular-marked/angular-marked.js"></script>
<script src="./bower_components/angular-cookies/angular-cookies.js"></script>
<script src="./bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="./bower_components/ngstorage/ngStorage.js"></script>
<script src="./bower_components/angular-ui-ace/ui-ace.js"></script>
<script src="./bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="./bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="./bower_components/json-formatter/dist/json-formatter.js"></script>
<script src="./bower_components/angular-ui-layout/ui-layout.js"></script>
<script src="./bower_components/json-schema-view/dist/json-schema-view.js"></script>
<script src="./bower_components/tv4/tv4.js"></script>
<script src="./bower_components/objectpath/lib/ObjectPath.js"></script>
<script src="./bower_components/swagger-converter/browser.js"></script>

<script src="bower_components/spark-md5/spark-md5.js"></script>
<script src="bower_components/traverse/traverse.js"></script>
<script src="bower_components/z-schema/dist/ZSchema-browser.js"></script>
<script src="bower_components/superagent/superagent.js"></script>
<script src="bower_components/json-refs/browser/json-refs.js"></script>
<script src="bower_components/swagger-tools/browser/swagger-tools.js"></script>
<script src="./bower_components/spark-md5/spark-md5.js"></script>
<script src="./bower_components/traverse/traverse.js"></script>
<script src="./bower_components/z-schema/dist/ZSchema-browser.js"></script>
<script src="./bower_components/superagent/superagent.js"></script>
<script src="./bower_components/json-refs/browser/json-refs.js"></script>
<script src="./bower_components/swagger-tools/browser/swagger-tools.js"></script>

<script src="bower_components/angular-schema-form/dist/schema-form.js"></script>
<script src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="bower_components/harmony-collections/harmony-collections.js"></script>
<script src="./bower_components/angular-schema-form/dist/schema-form.js"></script>
<script src="./bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="./bower_components/harmony-collections/harmony-collections.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/bootstrap.js"></script>
<script src="scripts/ace/themes/theme-atom_dark.js"></script>
<script src="scripts/ace/snippets/swagger.snippet.js"></script>
<script src="scripts/analytics/google.js"></script>
<script src="scripts/config/app.config.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/header.js"></script>
<script src="scripts/controllers/import-file.js"></script>
<script src="scripts/controllers/editor.js"></script>
<script src="scripts/controllers/preview.js"></script>
<script src="scripts/controllers/general-modal.js"></script>
<script src="scripts/controllers/importurl.js"></script>
<script src="scripts/controllers/paste-json.js"></script>
<script src="scripts/controllers/errorpresenter.js"></script>
<script src="scripts/controllers/openexamples.js"></script>
<script src="scripts/controllers/modal.js"></script>
<script src="scripts/controllers/security.js"></script>
<script src="scripts/directives/on-file-change.js"></script>
<script src="scripts/directives/path.js"></script>
<script src="scripts/directives/operation.js"></script>
<script src="scripts/directives/schemamodel.js"></script>
<script src="scripts/directives/stop-event.js"></script>
<script src="scripts/directives/scroll-into-view-when.js"></script>
<script src="scripts/directives/collapsewhen.js"></script>
<script src="scripts/directives/track-event.js"></script>
<script src="scripts/enums/defaults.js"></script>
<script src="scripts/enums/strings.js"></script>
<script src="scripts/filters/formdata.js"></script>
<script src="scripts/directives/tryoperation.js"></script>
<script src="scripts/services/sorter.js"></script>
<script src="scripts/services/tag-manager.js"></script>
<script src="scripts/services/autocomplete.js"></script>
<script src="scripts/services/fileloader.js"></script>
<script src="scripts/services/editor.js"></script>
<script src="scripts/services/builder.js"></script>
<script src="scripts/services/ast-manager.js"></script>
<script src="scripts/services/backend-health-check.js"></script>
<script src="scripts/services/codegen.js"></script>
<script src="scripts/services/focused-path.js"></script>
<script src="scripts/services/storage.js"></script>
<script src="scripts/services/local-storage.js"></script>
<script src="scripts/services/backend.js"></script>
<script src="scripts/services/keyword-map.js"></script>
<script src="scripts/services/preferences.js"></script>
<script src="scripts/services/auth-manager.js"></script>
<script src="scripts/services/embedded.js"></script>
<script src="scripts/services/analytics.js"></script>
<script src="scripts/router.js"></script>
<script src="scripts/plugins/jquery.scroll-into-view.js"></script>
<!-- build:js({.tmp,app}) ./scripts/scripts.js -->
<script src="./scripts/app.js"></script>
<script src="./scripts/templates.js"></script>
<script src="./scripts/bootstrap.js"></script>
<script src="./scripts/ace/themes/theme-atom_dark.js"></script>
<script src="./scripts/ace/snippets/swagger.snippet.js"></script>
<script src="./scripts/analytics/google.js"></script>
<script src="./scripts/config/app.config.js"></script>
<script src="./scripts/controllers/main.js"></script>
<script src="./scripts/controllers/header.js"></script>
<script src="./scripts/controllers/import-file.js"></script>
<script src="./scripts/controllers/editor.js"></script>
<script src="./scripts/controllers/preview.js"></script>
<script src="./scripts/controllers/general-modal.js"></script>
<script src="./scripts/controllers/importurl.js"></script>
<script src="./scripts/controllers/paste-json.js"></script>
<script src="./scripts/controllers/errorpresenter.js"></script>
<script src="./scripts/controllers/openexamples.js"></script>
<script src="./scripts/controllers/modal.js"></script>
<script src="./scripts/controllers/security.js"></script>
<script src="./scripts/directives/on-file-change.js"></script>
<script src="./scripts/directives/path.js"></script>
<script src="./scripts/directives/operation.js"></script>
<script src="./scripts/directives/schemamodel.js"></script>
<script src="./scripts/directives/stop-event.js"></script>
<script src="./scripts/directives/scroll-into-view-when.js"></script>
<script src="./scripts/directives/collapsewhen.js"></script>
<script src="./scripts/directives/track-event.js"></script>
<script src="./scripts/enums/defaults.js"></script>
<script src="./scripts/enums/strings.js"></script>
<script src="./scripts/filters/formdata.js"></script>
<script src="./scripts/directives/tryoperation.js"></script>
<script src="./scripts/services/sorter.js"></script>
<script src="./scripts/services/tag-manager.js"></script>
<script src="./scripts/services/autocomplete.js"></script>
<script src="./scripts/services/fileloader.js"></script>
<script src="./scripts/services/editor.js"></script>
<script src="./scripts/services/builder.js"></script>
<script src="./scripts/services/ast-manager.js"></script>
<script src="./scripts/services/backend-health-check.js"></script>
<script src="./scripts/services/codegen.js"></script>
<script src="./scripts/services/focused-path.js"></script>
<script src="./scripts/services/storage.js"></script>
<script src="./scripts/services/local-storage.js"></script>
<script src="./scripts/services/backend.js"></script>
<script src="./scripts/services/keyword-map.js"></script>
<script src="./scripts/services/preferences.js"></script>
<script src="./scripts/services/auth-manager.js"></script>
<script src="./scripts/services/embedded.js"></script>
<script src="./scripts/services/analytics.js"></script>
<script src="./scripts/router.js"></script>
<script src="./scripts/plugins/jquery.scroll-into-view.js"></script>
<!-- endbuild -->
</body>
</html>
10 changes: 8 additions & 2 deletions app/scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ $(function () {
window.SwaggerEditor.$defaults = embeddedDefaults;
angular.bootstrap(window.document, ['SwaggerEditor']);
} else {
$.getJSON('/config/defaults.json').done(function (resp) {
var rootPath = '';
if (window.location.pathname.lastIndexOf('/') !==
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what's going on here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$.getJSON('/config/defaults.json')

This make a request base on the url root. if we deploy the dist folder to sub path like http://domain.com/editor/index.html. Then it get the defaults.json by the url http://domain.com/config/defaults.json so throw a 404.

the window.location.pathname would be end with '/' or 'html' or a dirname like 'editor'. When it end with '/', it dosen't need to add a root path,just change the '/config/defaults.json' to './config/defaults.json' will be ok. When it end with 'html' or a dirname like 'editor' , the root path is the parent directory, so rootPath = pathname + '/../' . This logic fixes the defaults.json and the examples yaml 404 error, when deploy it in a sub folder or reverse proxy by nginx.

(window.location.pathname.length - 1)) {
rootPath = window.location.pathname + '/../';
}
$.getJSON(rootPath + './config/defaults.json').done(function (resp) {
window.SwaggerEditor.$defaults = resp;
angular.bootstrap(window.document, ['SwaggerEditor']);
}).fail(function () {
console.error('Failed to load defaults.json at', '/config/defaults.json');
console.error('Failed to load defaults.json at',
rootPath + './config/defaults.json');
});
}
});
7 changes: 6 additions & 1 deletion app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ SwaggerEditor.controller('MainCtrl', function MainCtrl($rootScope, $stateParams,

// If there is no saved YAML either, load the default example
} else if (!yaml) {
url = defaults.examplesFolder + defaults.exampleFiles[0];
var rootPath = '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what's going on here also?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above.

if (window.location.pathname.lastIndexOf('/') !==
(window.location.pathname.length - 1)) {
rootPath = window.location.pathname + '/../';
}
url = rootPath + defaults.examplesFolder + defaults.exampleFiles[0];
}

if (url) {
Expand Down