Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flanc/router-json

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flanc/router-json - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

50

index.js
"use strict";
/* istanbul ignore file */
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = exports.errorHandler = exports.path = void 0;
const router_commons_1 = require("flanc/router-commons");
const documentation_1 = require("flanc/router-commons/documentation");
let router;
exports.path = '/jsonapi';
function printDocumentation(req, res) {
res.set('Access-Control-Allow-Origin', '*');
res.status(200).json(documentation_1.render(router._spec));
function formatter(data) {
return (typeof data === 'string') ? data : JSON.stringify(data);
}
function errorHandler(err, req, res, next) {
if (!req.path.match(new RegExp(`^${exports.path}`))) {
next(err);
return;
function Router(app, RouterConstructor) {
const router = new RouterConstructor();
router._spec = {};
function printDocumentation(req, res) {
res.set('Access-Control-Allow-Origin', '*');
res.status(200).json(documentation_1.render(router._spec));
}
res.status(err.status || 500).send(err);
next();
}
exports.errorHandler = errorHandler;
function setupRouter(RouterConstructor) {
router = new RouterConstructor();
router._spec = {};
if (process.env.NODE_ENV !== 'production')
router.get('/docs', printDocumentation);
router.register = function register(route) {
router_commons_1.register(route, router, {
supportedMethods: ['get', 'post', 'patch', 'delete'],
responseHeaders: { 'content-type': 'application/json' },
formatError: (error) => formatter(error),
formatResponse: (response) => formatter(response),
});
};
router.start = function start() { };
router.stop = function stop() { };
return router;
}
exports.default = setupRouter;
function formatter(data) {
return (typeof data === 'string') ? data : JSON.stringify(data);
}
function register(route) {
router_commons_1.register(route, router, {
supportedMethods: ['get', 'post', 'patch', 'delete'],
responseHeaders: { 'content-type': 'application/json' },
formatError: (error) => formatter(error),
formatResponse: (response) => formatter(response),
});
}
exports.register = register;
exports.default = Router;
Router.defaultMountPath = '/jsonapi';

2

package.json
{
"name": "@flanc/router-json",
"version": "0.0.3",
"version": "0.0.4",
"description": "The openapi router for flanc apis",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc