-
Notifications
You must be signed in to change notification settings - Fork 99
Feature/eslint #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/eslint #156
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "loopback", | ||
| "rules": { | ||
| "max-len": ["error", 90, 4, { | ||
| "ignoreComments": true, | ||
| "ignoreUrls": true, | ||
| "ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)" | ||
| }] | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,17 +2,17 @@ | |
| /*! | ||
| * Adds dynamically-updated docs as /explorer | ||
| */ | ||
| var url = require('url'); | ||
| var path = require('path'); | ||
| var urlJoin = require('./lib/url-join'); | ||
| var _defaults = require('lodash').defaults; | ||
| var cors = require('cors'); | ||
| var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec; | ||
| var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist; | ||
| var STATIC_ROOT = path.join(__dirname, 'public'); | ||
|
|
||
| module.exports = explorer; | ||
| explorer.routes = routes; | ||
| var url = require('url'); | ||
| var path = require('path'); | ||
| var urlJoin = require('./lib/url-join'); | ||
| var _defaults = require('lodash').defaults; | ||
| var cors = require('cors'); | ||
| var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec; | ||
| var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist; | ||
| var STATIC_ROOT = path.join(__dirname, 'public'); | ||
|
|
||
| module.exports = explorer; | ||
| explorer.routes = routes; | ||
|
|
||
| /** | ||
| * Example usage: | ||
|
|
@@ -21,70 +21,70 @@ explorer.routes = routes; | |
| * explorer(app, options); | ||
| */ | ||
|
|
||
| function explorer(loopbackApplication, options) { | ||
| options = _defaults({}, options, { mountPath: '/explorer' }); | ||
| loopbackApplication.use(options.mountPath, routes(loopbackApplication, options)); | ||
| loopbackApplication.set('loopback-component-explorer', options); | ||
| } | ||
| function explorer(loopbackApplication, options) { | ||
| options = _defaults({}, options, { mountPath: '/explorer' }); | ||
| loopbackApplication.use(options.mountPath, routes(loopbackApplication, options)); | ||
| loopbackApplication.set('loopback-component-explorer', options); | ||
| } | ||
|
|
||
| function routes(loopbackApplication, options) { | ||
| var loopback = loopbackApplication.loopback; | ||
| var loopbackMajor = loopback && loopback.version && | ||
| function routes(loopbackApplication, options) { | ||
| var loopback = loopbackApplication.loopback; | ||
| var loopbackMajor = loopback && loopback.version && | ||
| loopback.version.split('.')[0] || 1; | ||
|
|
||
| if (loopbackMajor < 2) { | ||
| throw new Error('loopback-component-explorer requires loopback 2.0 or newer'); | ||
| } | ||
| if (loopbackMajor < 2) { | ||
| throw new Error('loopback-component-explorer requires loopback 2.0 or newer'); | ||
| } | ||
|
|
||
| options = _defaults({}, options, { | ||
| resourcePath: 'swagger.json', | ||
| apiInfo: loopbackApplication.get('apiInfo') || {}, | ||
| swaggerUI: true | ||
| }); | ||
| options = _defaults({}, options, { | ||
| resourcePath: 'swagger.json', | ||
| apiInfo: loopbackApplication.get('apiInfo') || {}, | ||
| swaggerUI: true, | ||
| }); | ||
|
|
||
| var router = new loopback.Router(); | ||
| var router = new loopback.Router(); | ||
|
|
||
| mountSwagger(loopbackApplication, router, options); | ||
| mountSwagger(loopbackApplication, router, options); | ||
|
|
||
| // config.json is loaded by swagger-ui. The server should respond | ||
| // with the relative URI of the resource doc. | ||
| router.get('/config.json', function(req, res) { | ||
| router.get('/config.json', function(req, res) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the same time, many comments were not reindented, which creates a real mess. |
||
| // Get the path we're mounted at. It's best to get this from the referer | ||
| // in case we're proxied at a deep path. | ||
| var source = url.parse(req.headers.referer || '').pathname; | ||
| var source = url.parse(req.headers.referer || '').pathname; | ||
| // If no referer is available, use the incoming url. | ||
| if (!source) { | ||
| source = req.originalUrl.replace(/\/config.json(\?.*)?$/, ''); | ||
| } | ||
| res.send({ | ||
| url: urlJoin(source, '/' + options.resourcePath) | ||
| if (!source) { | ||
| source = req.originalUrl.replace(/\/config.json(\?.*)?$/, ''); | ||
| } | ||
| res.send({ | ||
| url: urlJoin(source, '/' + options.resourcePath), | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| if (options.swaggerUI) { | ||
| if (options.swaggerUI) { | ||
| // Allow specifying a static file roots for swagger files. Any files in | ||
| // these folders will override those in the swagger-ui distribution. | ||
| // In this way one could e.g. make changes to index.html without having | ||
| // to worry about constantly pulling in JS updates. | ||
| if (options.uiDirs) { | ||
| if (typeof options.uiDirs === 'string') { | ||
| router.use(loopback.static(options.uiDirs)); | ||
| } else if (Array.isArray(options.uiDirs)) { | ||
| options.uiDirs.forEach(function(dir) { | ||
| router.use(loopback.static(dir)); | ||
| }); | ||
| if (options.uiDirs) { | ||
| if (typeof options.uiDirs === 'string') { | ||
| router.use(loopback.static(options.uiDirs)); | ||
| } else if (Array.isArray(options.uiDirs)) { | ||
| options.uiDirs.forEach(function(dir) { | ||
| router.use(loopback.static(dir)); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // File in node_modules are overridden by a few customizations | ||
| router.use(loopback.static(STATIC_ROOT)); | ||
| router.use(loopback.static(STATIC_ROOT)); | ||
|
|
||
| // Swagger UI distribution | ||
| router.use(loopback.static(SWAGGER_UI_ROOT)); | ||
| } | ||
| router.use(loopback.static(SWAGGER_UI_ROOT)); | ||
| } | ||
|
|
||
| return router; | ||
| } | ||
| return router; | ||
| } | ||
|
|
||
| /** | ||
| * Setup Swagger documentation on the given express app. | ||
|
|
@@ -95,30 +95,30 @@ function routes(loopbackApplication, options) { | |
| * swagger documentation. | ||
| * @param {Object} opts Options. | ||
| */ | ||
| function mountSwagger(loopbackApplication, swaggerApp, opts) { | ||
| var swaggerObject = createSwaggerObject(loopbackApplication, opts); | ||
| function mountSwagger(loopbackApplication, swaggerApp, opts) { | ||
| var swaggerObject = createSwaggerObject(loopbackApplication, opts); | ||
|
|
||
| // listening to modelRemoted event for updating the swaggerObject | ||
| // with the newly created model to appear in the Swagger UI. | ||
| loopbackApplication.on('modelRemoted', function() { | ||
| swaggerObject = createSwaggerObject(loopbackApplication, opts); | ||
| }); | ||
| loopbackApplication.on('modelRemoted', function() { | ||
| swaggerObject = createSwaggerObject(loopbackApplication, opts); | ||
| }); | ||
|
|
||
| var resourcePath = opts && opts.resourcePath || 'swagger.json'; | ||
| if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath; | ||
| var resourcePath = opts && opts.resourcePath || 'swagger.json'; | ||
| if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath; | ||
|
|
||
| var remotes = loopbackApplication.remotes(); | ||
| setupCors(swaggerApp, remotes); | ||
| var remotes = loopbackApplication.remotes(); | ||
| setupCors(swaggerApp, remotes); | ||
|
|
||
| swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) { | ||
| res.status(200).send(swaggerObject); | ||
| }); | ||
| } | ||
| swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) { | ||
| res.status(200).send(swaggerObject); | ||
| }); | ||
| } | ||
|
|
||
| function setupCors(swaggerApp, remotes) { | ||
| var corsOptions = remotes.options && remotes.options.cors || | ||
| function setupCors(swaggerApp, remotes) { | ||
| var corsOptions = remotes.options && remotes.options.cors || | ||
| { origin: true, credentials: true }; | ||
|
|
||
| // TODO(bajtos) Skip CORS when remotes.options.cors === false | ||
| swaggerApp.use(cors(corsOptions)); | ||
| } | ||
| swaggerApp.use(cors(corsOptions)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Amir-61 @superkhau this has re-indented whole
index.jsby one level of nesting :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's weird! Sorry I did not notice that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos I didn't notice it. Not a big deal though, let's submit another PR to fix it. ;)