This repository has been archived on 2020-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
Timo Hocker bd63607477 update-scanner: automatic update
@sapphirecode/eslint-config-ts: 1.1.9 ==> 1.1.10 minor
@sapphirecode/modelling: 1.0.38 ==> 1.0.39 minor
eslint: 6.8.0 ==> 7.1.0 major
2020-05-28 08:51:43 +02:00
2020-05-06 08:35:28 +02:00
2020-04-03 18:50:08 +02:00
fix
2020-05-06 07:33:07 +02:00
2020-04-03 17:51:25 +02:00
2020-05-15 13:16:26 +02:00
2020-05-02 21:51:56 +02:00
2020-02-08 16:13:50 +01:00
2020-05-05 19:23:36 +02:00
2020-02-05 20:13:43 +01:00
fix
2020-05-06 07:33:07 +02:00
2020-05-28 08:51:43 +02:00

Requestor

Split express request handlers into individual files to make your api a little more structured.

Installation

npmrc:

used to set the registry for @scode

@scode:registry=https://npm.scode.ovh

install the package:

npm i --save @scode/requestor

Usage

The path to which the individual modules respond is defined by their name.

'.' is used as path separator.

method-subdir.subdir.subdir.js

method can be any of [post, get, put, delete, all]

to avoid names like get-.js root is used for the root directory (get-root.js)

index.js:

const requestor = require('requestor');
const express = require('express');

const app = express();
requestor(app, 'api', {opts: {foo: 'bar'}});
app.listen(3000);

api/get-root.js

// will respond to get requests on /
module.exports = (req, res, next, opts) => {
  res.send(opts.foo);
};

api/post-subfolder.js

// will respond to post requests on /subfolder/
module.exports = (req, res, next, opts) => {
  res.send(opts.foo);
};

optionally, you can set a subdirectory for all requests

//...

requestor(app, 'api', {subdir: 'subdir'});

// requests that before responded to /foo/bar/ will now respond to /subdir/foo/bar/
Description
No description provided
Readme 671 KiB
Languages
TypeScript 94.5%
JavaScript 5.5%