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

express-api-middleware

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-api-middleware - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

lib/namedRoute.d.ts

1

lib/index.d.ts

@@ -0,2 +1,3 @@

export * from './namedRoute';
export * from './rest';
export * from './crud';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./namedRoute"), exports);
tslib_1.__exportStar(require("./rest"), exports);
tslib_1.__exportStar(require("./crud"), exports);

24

lib/rest.js

@@ -18,3 +18,3 @@ "use strict";

}
function buildBrowserScript(routers) {
function buildBrowserScript(baseUrl, routers) {
const apis = [];

@@ -28,11 +28,16 @@ function addHandler(api, handler, path, params) {

const hasBody = httpMethod !== 'GET' && httpMethod !== 'HEAD';
params = params.filter((p) => typeof (p) === 'string');
if (hasBody)
params.push('body');
params.forEach((p) => {
path = path.replace(':' + p, '${encodeURIComponent(' + p + ')}');
const regexp = new RegExp(':' + p + '(\\(.+\\))?', 'g');
path = path.replace(regexp, '${encodeURIComponent(' + p + ')}');
});
let name = handler.name;
if (handler.name === 'namedRouteFn')
name = handler.handle.route_name;
const method = {
name: handler.name,
name: name,
params,
path: api.url.replace(/\/$/, '') + '/' + path.replace(/^\//, ''),
path: (api.url === '' ? '' : api.url.replace(/\/$/, '') + '/') + path.replace(/^\//, ''),
method: handler.method.toUpperCase(),

@@ -69,8 +74,13 @@ hasBody,

const tmpl = handlebars_1.default.compile(fs_1.readFileSync(path_1.resolve(__dirname, 'browser.js.hbs'), 'utf-8'));
return tmpl({ className: 'API', apis });
return tmpl({
className: 'API',
baseUrl,
apis: apis.filter((api) => api.name !== ''),
defaultApi: apis.find((api) => api.name === ''),
});
}
return (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
root = root.replace(/\/$/, '');
if (util_1.isNullOrUndefined(browserScript)) {
browserScript = buildBrowserScript(routers);
console.dir(require.resolve('handlebars'));
browserScript = buildBrowserScript(root, routers);
// req.app.use(root + '/handlebars', require.resolve('handlebars'));

@@ -77,0 +87,0 @@ req.app.get(root + '/browser.js', getBrowserScript);

{
"name": "express-api-middleware",
"version": "0.1.1",
"version": "0.1.2",
"description": "Automatically generate browser code based on express REST API routes",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

Sorry, the diff of this file is not supported yet

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