New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kequapp

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kequapp - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

dist/addons/send-file.js

@@ -23,4 +23,3 @@ "use strict";

try {
const fileInfo = fs_1.default.statSync(location);
if (!fileInfo.isFile())
if (!fs_1.default.statSync(location).isFile())
throw new Error();

@@ -27,0 +26,0 @@ }

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

function staticFiles(options = {}) {
const config = getConfig(options);
const config = setupConfig(options);
return function ({ req, res, params }) {

@@ -52,26 +52,24 @@ return __awaiter(this, void 0, void 0, function* () {

}
function getConfig(options) {
const config = Object.assign({}, DEFAULT_OPTIONS);
if (options.dir) {
if (typeof options.dir !== 'string') {
function setupConfig(options) {
const config = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
if (config.dir) {
if (typeof config.dir !== 'string') {
throw new Error('staticFiles options.dir must be a string');
}
config.dir = options.dir;
}
if (options.exclude) {
if (!Array.isArray(options.exclude)) {
if (config.exclude) {
if (!Array.isArray(config.exclude)) {
throw new Error('staticFiles options.exclude must be an array');
}
for (const value of options.exclude) {
for (const value of config.exclude) {
if (typeof value !== 'string') {
throw new Error('staticFiles options.exclude value must be a string');
}
config.exclude.push(path_1.default.join(value));
}
}
if (options.mime) {
if (typeof options.mime !== 'object' || options.mime === null) {
if (config.mime) {
if (typeof config.mime !== 'object' || config.mime === null) {
throw new Error('staticFiles options.mime must be an object');
}
for (const value of Object.values(options.mime)) {
for (const value of Object.values(config.mime)) {
if (typeof value !== 'string') {

@@ -78,0 +76,0 @@ throw new Error('staticFiles options.mime value must be a string');

{
"name": "kequapp",
"version": "0.1.2",
"version": "0.1.3",
"description": "Versatile, non-intrusive, tiny webapp framework",

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

# Introduction
This is a request listener for use with Node's [`http`](https://nodejs.org/api/http.html) library.
This is a request listener for use with Node's [`http`](https://nodejs.org/api/http.html) and [`https`](https://nodejs.org/api/https.html) libraries.

@@ -11,3 +11,3 @@ When you use `createServer` in a node application it gives you a callback to make use of incoming requests and deliver server responses. This framework is a way to use all of the included features of `createServer` without overloading or changing any of it's behavior or functionality.

* Includes simple static file serving
* Includes inject tool for testing
* Includes inject tool for tests
* Handle any request

@@ -20,3 +20,3 @@ * Handle thrown errors

* Fast
* Zero dependencies
* No dependencies <3

@@ -44,9 +44,9 @@ # Initialization

The route shown above will respond to all `'GET'` requests made to the base of the application, at `'/'`. Otherwise your application will respond gracefully with `404` not found.
The route shown above will respond to all `'GET'` requests made to the base of the application, at `'/'`. Otherwise our application will respond gracefully with `404` not found.
A route optionally specifies both a method (`'GET'`, `'POST'`, etc...) and url. Methods can be anything you want, doesn't have to be one of the well known ones and url is anything you want to act on. Following this is any number of handlers you want associated with the route.
A route optionally specifies both a method (`'GET'`, `'POST'`, etc...) and url. Methods can be anything we want, doesn't have to be one of the well known ones and url is anything we want to act on. Following this is any number of handlers we want associated with the route.
You may specify a branch of the application, which will cause all child routes to adopt the given url and handlers. Any route can have any number of handlers, handlers run in sequence, and terminate if one of them returns a value, throws an error, or finalizes the response.
In this way keep in mind you can respond to a request anywhere you want. The rest of the handlers will be ignored.
In this way keep in mind we can respond to a request anywhere we want. The rest of the handlers will be ignored.

@@ -95,3 +95,3 @@ # Branch & Route

The node [`req`](https://nodejs.org/api/http.html#class-httpclientrequest) object. It is not modified by this framework so you can rely on the official documentation to use it.
The node [`req`](https://nodejs.org/api/http.html#class-httpclientrequest) object. It is not modified by this framework so we can rely on the official documentation to use it.

@@ -102,9 +102,9 @@ This represents the client request.

The node [`res`](https://nodejs.org/api/http.html#class-httpserverresponse) object. It is not modified by this framework so you can rely on the official documentation to use it.
The node [`res`](https://nodejs.org/api/http.html#class-httpserverresponse) object. It is not modified by this framework so we can rely on the official documentation to use it.
This represents your response.
This represents our response.
### url
If you need to know more about what the client is looking at in the url bar you can do so with this. It is a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) instance generated from the `req` object.
If we need to know more about what the client is looking at in the url bar we can do so with this. It is a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) instance generated from the `req` object.

@@ -125,9 +125,9 @@ Useful for examining the querystring for example by digging into it's [`searchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).

A place to store variables derived by handlers, you might use these variables elsewhere in the handler lifecycle. Make changes here whenever you want and populate it with anything.
A place to store variables derived by handlers, we might use these variables elsewhere in the handler lifecycle. Make changes here whenever you want and populate it with anything.
Useful for storing authentication details for example, or any information that is needed amongst handlers later on.
Useful for storing authentication details for example, or any information that is needed amongst our handlers later on.
### params
When defining a route you can specify parameters to extract by prefixing a `':'` character in the url. If you specify a route such as `'/users/:userId'` you will have a parameter called `'userId'`. A `'*'` character can be used to accept anything, and `'**'` can be used to accept anything for the remainder of the url.
When defining a route we can specify parameters to extract by prefixing a `':'` character in the url. If we specify a route such as `'/users/:userId'` we will have a parameter called `'userId'` here. A `'*'` character can be used to accept anything, and `'**'` can be used to accept anything for the remainder of the url.

@@ -138,3 +138,3 @@ Param values are always a string.

Node delivers the body of a request in chunks. It is not always necessary to wait for the request to finish before we begin processing it. In most cases we just want the data though and therefore a helper method `getBody()` is provided which you may use to await body parameters from the completed request.
Node delivers the body of a request in chunks. It is not always necessary to wait for the request to finish before we begin processing it. In most cases we just want the data though and therefore a helper method `getBody()` is provided which we may use to await body parameters from the completed request.

@@ -166,3 +166,3 @@ ```javascript

As mentioned this is very simply a logger to use throughout the project. Debug messages are sent for every request, `500` errors are logged here. As well as anything else you want to use it for in your project. If not specfied the default is `console`.
As mentioned this is very simply a logger to use throughout the project. Debug messages are sent for every request, `500` errors are logged here. As well as anything else we want to use it for in our project. If not specfied the default is `console`.

@@ -175,5 +175,5 @@ ### renderers

In most cases you want to send text, or maybe an image, a file, or whatever. The renderer is chosen based on the `'Content-Type'` header that has been set. That is why in our original example it was possible to set the `'Content-Type'` to `'application/json'` and then simply return javascript objects from our handlers. The renderer accepts any payload that you give it and formats it to be sent to the client.
In most cases we want to send text, or maybe an image, a file, or whatever. The renderer is chosen based on the `'Content-Type'` header that has been set. That is why in our original example it was possible to set the `'Content-Type'` to `'application/json'` and then simply return javascript objects from our handlers. The renderer accepts any payload that we give it and formats it to be sent to the client.
Abstracting rendering away from business logic is convenient but if you want you can skip rendering by finalizing the response yourself. In this way no renderer is needed.
Abstracting rendering away from business logic is convenient but if we want we can skip rendering by finalizing the response yourself. In this way no renderer is needed.

@@ -207,3 +207,3 @@ ```javascript

Some renderers are built-in already, specifically for `'text/plain'` (which is also the default) and `'application/json'`, but these can be overridden or extended by providing `renderers` while creating your app.
Some renderers are built-in already, specifically for `'text/plain'` (which is also the default) and `'application/json'`, but these can be overridden or extended by providing `renderers` while creating our app.

@@ -244,3 +244,3 @@ ```javascript

For as example of how to write a error handler see the existing one in this repo's [`/src/built-in`](https://github.com/Kequc/kequapp/tree/main/src/built-in) directory.
For an example of how to write a error handler see the existing one in this repo's [`/src/built-in`](https://github.com/Kequc/kequapp/tree/main/src/built-in) directory.

@@ -251,3 +251,3 @@ ### autoHead

If no matching `HEAD` route is found the matching `GET` route is triggered in it's place. It is then the responsibility of your application usually in the renderer to detect a `HEAD` request and then send no body in the response.
If no matching `HEAD` route is found the matching `GET` route is triggered in it's place. It is then the responsibility of our application usually in the renderer to detect a `HEAD` request and then send no body in the response.

@@ -258,7 +258,7 @@ This behavior can be disabled by setting `autoHead` to `false`.

There are a few helper utilities you can use while building your application which should make some processes easier.
There are a few helper utilities we can use while building our application which should make some processes easier.
### Ex
Any unhandled error will result in a `500` internal server error response to the client. If you would like to send an error with a different status code there is a helper available. This makes it possible to utilize any status code `400` and above.
Any unhandled error will result in a `500` internal server error response to the client. If we would like to send an error with a different status code there is a helper available. This makes it possible to utilize any status code `400` and above.

@@ -283,7 +283,7 @@ ```javascript

A rudimentary handler for delivering files relative to your project directory.
A rudimentary handler for delivering files relative to our project directory.
It utilizes the `'**'` parameter as defined by your route to build a valid path, and will try to guess a content type for each file based on their file extension.
It utilizes the `'**'` parameter as defined by our route to build a valid path, and will try to guess a content type for each file based on their file extension.
If no `dir` is specified then `'/public'` is used by default. Exclusions can be provided if you want to ignore some files or directories using `exclude`. If there are files included which have unusual file extensions more `mime` types can be provided.
If no `dir` is specified then `'/public'` is used by default. Exclusions can be provided if we want to ignore some files or directories using `exclude`. If there are files included which have unusual file extensions more `mime` types can be provided.

@@ -377,3 +377,3 @@ ```javascript

By default the data received is pushed through some body normalization. This is so that the body you receive is in a format you expect and becomes easier to work with.
By default the data received is pushed through some body normalization. This is so that the body we receive is in a format we expect and becomes easier to work with.

@@ -404,3 +404,3 @@ Disable body normalization with either `raw` or `skipNormalize`.

The provided list of fields are not `null` or `undefined`. It's a quick way to throw a `422` unprocessable entity error. These fields might still be empty, but at least something was sent and you can operate on it. When a `required` field is also an `arrays` field the array is sure to have at least one value.
The provided list of fields are not `null` or `undefined`. It's a quick way to throw a `422` unprocessable entity error. These fields might still be empty, but at least something was sent and we can operate on it. When a `required` field is also an `arrays` field the array is sure to have at least one value.

@@ -423,3 +423,3 @@ ### numbers

After all other normalization is completed and `validate` has passed, this method is run to further format the response in any way you need.
After all other normalization is completed and `validate` has passed, this method is run to further format the response in any way we need.

@@ -488,7 +488,7 @@ The returned value will be the final result.

You may test your application without starting a server by using the `inject()` helper tool. The first parameter is your app, then options largely used to populate the request.
We may test our application without starting a server by using the `inject()` helper tool. The first parameter is our app, then options largely used to populate the request.
Returned `req` and `res` objects are from the npm [`mock-req`](https://www.npmjs.com/package/mock-req) and [`mock-res`](https://www.npmjs.com/package/mock-res) modules respectively. Ensure you have both installed in your dev dependencies if you are using this tool.
It also returns `getResponse()` which may be used to wait for your application to respond. You may instead inspect what your application is doing using the `req`, and `res` objects.
It also returns `getResponse()` which may be used to wait for our application to respond. We may instead inspect what our application is doing using the `req`, and `res` objects.

@@ -519,7 +519,7 @@

Overrides the configuration of your application.
Overrides the configuration options of our application.
### body
All requests are automatically finalized when using `inject()` unless you set `body` to `null`. Doing so will allow you to write to the stream.
All requests are automatically finalized when using `inject()` unless we set `body` to `null`. Doing so will allow us to write to the stream.

@@ -558,4 +558,4 @@ The following two examples are the same.

And that's it. This should be ample for constructing an application that does anything you could ever want it to do. At least for version `0.1.*` I think it's okay.
And that's it. This should be ample for constructing an application that does anything we could ever want it to do. At least for version `0.1.*` I think it's okay.
Please feel free to contribute or create issue tickets on the github page. Tell me what is missing.
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