diff --git a/packages/streams/nmea0183-signalk.js b/packages/streams/nmea0183-signalk.js index 1afcc5db8..531f4945a 100644 --- a/packages/streams/nmea0183-signalk.js +++ b/packages/streams/nmea0183-signalk.js @@ -39,8 +39,9 @@ function Nmea0183ToSignalK(options) { Transform.call(this, { objectMode: true, }) - this.debug = (options.createDebug || require('debug'))('signalk:streams:nmea0183-signalk') - + this.debug = (options.createDebug || require('debug'))( + 'signalk:streams:nmea0183-signalk' + ) this.parser = new Parser(options) this.n2kParser = new FromPgn(options) diff --git a/src/api/course/index.ts b/src/api/course/index.ts index 4e2d79d0f..093a3535b 100644 --- a/src/api/course/index.ts +++ b/src/api/course/index.ts @@ -1,7 +1,6 @@ -import Debug from 'debug' -const debug = Debug('signalk:courseApi') -// import { createDebug } from './debug' -// const debug = createDebug('signalk:courseApi') +import { createDebug } from '../../debug' +const debug = createDebug('signalk:courseApi') + import { FullSignalK } from '@signalk/signalk-schema' import { Application, Request, Response } from 'express' import _ from 'lodash' @@ -10,9 +9,9 @@ import { WithConfig } from '../../app' import { WithSecurityStrategy } from '../../security' import { Position } from '../../types' +import { Responses } from '../' import { Store } from '../../serverstate/store' import { Route } from '../resources/types' -import { Responses } from '../' const SIGNALK_API_PATH = `/signalk/v1/api` const COURSE_API_PATH = `${SIGNALK_API_PATH}/vessels/self/navigation/course` diff --git a/src/api/index.ts b/src/api/index.ts index 02232b2cc..584c3645a 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,43 +1,43 @@ export interface ApiResponse { - state: 'FAILED' | 'COMPLETED' | 'PENDING' - statusCode: number - message: string - requestId?: string - href?: string - token?: string + state: 'FAILED' | 'COMPLETED' | 'PENDING' + statusCode: number + message: string + requestId?: string + href?: string + token?: string } export const Responses = { - ok: { - state: 'COMPLETED', - statusCode: 200, - message: 'OK' - }, - invalid: { - state: 'FAILED', - statusCode: 406, - message: `Invalid Data supplied.` - }, - unauthorised: { - state: 'FAILED', - statusCode: 403, - message: 'Unauthorised' - }, - notFound: { - state: 'FAILED', - statusCode: 404, - message: 'Resource not found.' - } + ok: { + state: 'COMPLETED', + statusCode: 200, + message: 'OK' + }, + invalid: { + state: 'FAILED', + statusCode: 406, + message: `Invalid Data supplied.` + }, + unauthorised: { + state: 'FAILED', + statusCode: 403, + message: 'Unauthorised' + }, + notFound: { + state: 'FAILED', + statusCode: 404, + message: 'Resource not found.' + } } // returns true if target path is an API request -export function isApiRequest(path:string): boolean { - if ( - path.split('/')[4] === 'resources' || // resources API - path.indexOf('/navigation/course/') !== -1 // course API - ) { - return true - } else { - return false - } -} \ No newline at end of file +export function isApiRequest(path: string): boolean { + if ( + path.split('/')[4] === 'resources' || // resources API + path.indexOf('/navigation/course/') !== -1 // course API + ) { + return true + } else { + return false + } +} diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 327d9befc..a260010ab 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -1,7 +1,5 @@ -import Debug from 'debug' -const debug = Debug('signalk:resourcesApi') -// import { createDebug } from './debug' -// const debug = createDebug('signalk:resourcesApi') +import { createDebug } from '../../debug' +const debug = createDebug('signalk:resourcesApi') import { ResourceProvider, @@ -11,7 +9,7 @@ import { import { Application, NextFunction, Request, Response } from 'express' import { v4 as uuidv4 } from 'uuid' -//import { SignalKMessageHub } from '../../app' +// import { SignalKMessageHub } from '../../app' import { WithSecurityStrategy } from '../../security' import { Responses } from '../' @@ -21,13 +19,11 @@ import { validate } from './validate' const SIGNALK_API_PATH = `/signalk/v1/api` const UUID_PREFIX = 'urn:mrn:signalk:uuid:' -interface ResourceApplication - extends Application, - WithSecurityStrategy { - handleMessage: (id: string, data: any) => void - } +interface ResourceApplication extends Application, WithSecurityStrategy { + handleMessage: (id: string, data: any) => void +} -export class Resources { +export class ResourcesApi { private resProvider: { [key: string]: ResourceProviderMethods | null } = {} private server: ResourceApplication diff --git a/src/index.ts b/src/index.ts index 2b472620b..2f659cfa1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,7 @@ import SubscriptionManager from './subscriptionmanager' import { Delta } from './types' import { CourseApi } from './api/course' -import { Resources } from './api/resources' +import { ResourcesApi } from './api/resources' const debug = createDebug('signalk-server') @@ -80,7 +80,7 @@ class Server { require('./serverroutes')(app, saveSecurityConfig, getSecurityConfig) require('./put').start(app) - app.resourcesApi = new Resources(app) + app.resourcesApi = new ResourcesApi(app) const courseApi = new CourseApi(app) app.signalk = new FullSignalK(app.selfId, app.selfType) diff --git a/src/put.js b/src/put.js index 36df6083d..bb91dc7ab 100644 --- a/src/put.js +++ b/src/put.js @@ -5,7 +5,7 @@ const { v4: uuidv4 } = require('uuid') const { createRequest, updateRequest } = require('./requestResponse') const skConfig = require('./config/config') -const {isApiRequest} = require('./api') +const { isApiRequest } = require('./api') const pathPrefix = '/signalk' const versionPrefix = '/v1' @@ -33,13 +33,12 @@ module.exports = { app.deRegisterActionHandler = deRegisterActionHandler app.put(apiPathPrefix + '*', function(req, res, next) { - // check for resources API, course API, etc request if (isApiRequest(req.path)) { next() return } - + let path = String(req.path).replace(apiPathPrefix, '') const value = req.body diff --git a/src/security.ts b/src/security.ts index b75c87446..75a60fbd8 100644 --- a/src/security.ts +++ b/src/security.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Request } from 'express' import { chmodSync, existsSync, @@ -30,7 +31,6 @@ import { Mode } from 'stat-mode' import { WithConfig } from './app' import { createDebug } from './debug' import dummysecurity from './dummysecurity' -import { Request } from 'express' const debug = createDebug('signalk-server:security') export interface WithSecurityStrategy {