Skip to content

Commit 3dbf941

Browse files
committed
Init
0 parents  commit 3dbf941

File tree

14 files changed

+1305
-0
lines changed

14 files changed

+1305
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
node_modules
3+
npm-debug.log

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
npm-debug.log
4+
examples
5+
test

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bracketSpacing": false,
3+
"eslintIntegration": true,
4+
"singleQuote": true
5+
}

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at go@linklet.run. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Linklet Contributor Guide
2+
3+
Excited about Linklet and want to make it better? We’re excited too!
4+
5+
Linklet is build for developers just like you, striving to create tools and libraries around HTTP based Microservices. We welcome anyone who wants to contribute or provide constructive feedback, no matter the level of experience. If you want to help but don't know where to start, let us know, and we'll find something for you.
6+
7+
Here are some ways to contribute to the project, from easiest to most difficult:
8+
9+
* [Reporting bugs](#reporting-bugs)
10+
* [Improving the documentation](#improving-the-documentation)
11+
* [Responding to issues](#responding-to-issues)
12+
* [Bug fixes](#bug-fixes)
13+
* [Suggesting features](#suggesting-features)
14+
15+
## Issues
16+
17+
### Reporting bugs
18+
19+
If you encounter a bug, please file an issue on GitHub via the repository. If an issue you have is already reported, please add additional information or add a 👍 reaction to indicate your agreement.
20+
21+
While we will try to be as helpful as we can on any issue reported, please include the following to maximize the chances of a quick fix:
22+
23+
1. **Intended outcome:** What you were trying to accomplish when the bug occurred, and as much code as possible related to the source of the problem.
24+
2. **Actual outcome:** A description of what actually happened, including a screenshot or copy-paste of any related error messages, logs, or other output that might be related.
25+
3. **How to reproduce the issue:** Instructions for how the issue can be reproduced by a maintainer or contributor.
26+
27+
Creating a good reproduction really helps contributors investigate and resolve your issue quickly.
28+
29+
### Improving the documentation
30+
31+
Improving the documentation, examples, and other open source content can be the easiest way to contribute to the library. If you see a piece of content that can be better, open a PR with an improvement, no matter how small! If you would like to suggest a big change or major rewrite, we’d love to hear your ideas but please open an issue for discussion before writing the PR.
32+
33+
### Responding to issues
34+
35+
In addition to reporting issues, a great way to contribute to Linklet is to respond to other peoples' issues and try to identify the problem or help them work around it. If you’re interested in taking a more active role in this process, please go ahead and respond to issues.
36+
37+
### Bug fixes
38+
39+
For a bug fix change (less than 30 lines of code changed), feel free to open a pull request. We’ll try to merge it as fast as possible and ideally publish a new release on the same day. The only requirement is, make sure you also add a test that verifies the bug you are trying to fix.
40+
41+
### Suggesting features
42+
43+
Most of the features in Linklet came from suggestions by you! We welcome any ideas about how to make Linklet better for your use case.
44+
45+
### Code review guidelines
46+
47+
Here are some things we look for:
48+
49+
1. **Required CI checks pass.** This is a prerequisite for the review, and it is the PR author's responsibility.
50+
2. **Simplicity.** If there are too many files, redundant functions, or complex lines of code, suggest a simpler way to do the same thing. In particular, avoid implementing an overly general solution when a simple, small, and pragmatic fix will do.
51+
3. **Testing.** Do the tests ensure this code won’t break when other stuff changes.
52+
4. **No unnecessary or unrelated changes.** PRs shouldn’t come with random formatting changes, especially in unrelated parts of the code.
53+
5. **Code has appropriate comments.** Code should be commented, or written in a clear “self-documenting” way.
54+
55+
## New contributors
56+
57+
If you want to contribute to Linklet, but aren't quite sure where to start, take a look at the [roadmap and design docs](docs/ROADMAP.md). Just pick one of the upcoming features that you're interested in, and start working on it. If the design doc isn't clear enough (which it probably won't be), open an issue thread so we can discuss it.

ISSUE_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Intended outcome:
2+
What you were trying to accomplish when the bug occurred, and as much code as possible related to the source of the problem.
3+
4+
# Actual outcome:
5+
A description of what actually happened, including a screenshot or copy-paste of any related error messages, logs, or other output that might be related.
6+
7+
# How to reproduce the issue:
8+
Instructions for how the issue can be reproduced by a maintainer or contributor.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2017 CodeCommission / Mike Bild
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Linklet Higher-Order HTTP Handler
2+
3+
## Documentation
4+
5+
* [Linklet Microservice Documentation](https://github.com/CodeCommission/linklet/tree/master/docs)
6+
* [Linklet Examples](https://github.com/codecommission/linklet-examples)
7+
* [Introduction to NodeJS](https://github.com/mikebild/introduction-nodejs)
8+
9+
## How to use it in my project?
10+
11+
Being stable and inventive and have a look to our [Linklet examples](https://github.com/codecommission/linklet-examples).
12+
13+
## Contributors
14+
15+
Every participation is welcome, just read [CONTRIBUTING](CONTRIBUTING.md) and make your first PR!
16+
17+
## Issue Reporting
18+
19+
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public [GitHub issue tracker](https://github.com/codecommission/linklet-higher-handlers/issues).
20+
21+
## License
22+
23+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
24+
25+
## Thanks
26+
27+
You like this and you want to see what coming next? Follow us on Twitter [`@linklet_run`](https://twitter.com/linklet_run).
28+
29+
Enjoy!

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports.withParams = require('./with-params');
2+
module.exports.withRoute = require('./with-route');

lib/with-params.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const url = require('url');
2+
const pathToRegexp = require('path-to-regexp');
3+
4+
module.exports = ({path}) => handler => (req, res) => {
5+
req.hasParamMatch = false;
6+
const uri = url.parse(req.url, true);
7+
const paramKeys = [];
8+
const pathMatchingPattern = pathToRegexp(path, paramKeys);
9+
10+
const isPatternMatchesPath = pathMatchingPattern.exec(
11+
req.url.replace(uri.search, '')
12+
);
13+
14+
if (!isPatternMatchesPath) return handler(req, res);
15+
if (!isPatternMatchesPath.length) return handler(req, res);
16+
17+
req.hasParamMatch = true;
18+
const paramValues = isPatternMatchesPath.splice(
19+
1,
20+
isPatternMatchesPath.length - 1
21+
);
22+
23+
req.params = paramKeys.reduce((state, next, idx) => {
24+
state[next.name] = paramValues[idx];
25+
return state;
26+
}, {});
27+
28+
return handler(req, res);
29+
};

0 commit comments

Comments
 (0)