@tinyhttp/app 2.0.19 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +4 -3
- package/dist/extend.d.ts +3 -3
- package/dist/index.d.ts +9 -9
- package/dist/index.js +4 -4
- package/dist/onError.d.ts +2 -2
- package/dist/request.d.ts +10 -4
- package/dist/response.d.ts +2 -2
- package/package.json +7 -8
package/dist/app.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
|
-
import type { Request } from './request';
|
|
4
|
-
import type { Response } from './response';
|
|
5
|
-
import type { ErrorHandler } from './onError';
|
|
3
|
+
import type { Request } from './request.js';
|
|
4
|
+
import type { Response } from './response.js';
|
|
5
|
+
import type { ErrorHandler } from './onError.js';
|
|
6
6
|
import { Middleware, Handler, NextFunction, Router, UseMethodParams } from '@tinyhttp/router';
|
|
7
7
|
/**
|
|
8
8
|
* tinyhttp App has a few settings for toggling features
|
|
@@ -13,6 +13,7 @@ export declare type AppSettings = Partial<{
|
|
|
13
13
|
bindAppToReqRes: boolean;
|
|
14
14
|
xPoweredBy: string | boolean;
|
|
15
15
|
enableReqRoute: boolean;
|
|
16
|
+
views: string;
|
|
16
17
|
}>;
|
|
17
18
|
/**
|
|
18
19
|
* Function that processes the template
|
package/dist/extend.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Request } from './request';
|
|
1
|
+
import { Request } from './request.js';
|
|
2
2
|
import type { NextFunction } from '@tinyhttp/router';
|
|
3
|
-
import type { Response } from './response';
|
|
4
|
-
import { App } from './app';
|
|
3
|
+
import type { Response } from './response.js';
|
|
4
|
+
import { App } from './app.js';
|
|
5
5
|
/**
|
|
6
6
|
* Extends Request and Response objects with custom properties and methods
|
|
7
7
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { App } from './app';
|
|
2
|
-
export type { AppSettings, TemplateEngineOptions, TemplateFunc } from './app';
|
|
3
|
-
export * from './request';
|
|
4
|
-
import type { Request } from './request';
|
|
5
|
-
export * from './response';
|
|
6
|
-
import type { Response } from './response';
|
|
7
|
-
export { extendMiddleware } from './extend';
|
|
8
|
-
export { onErrorHandler } from './onError';
|
|
9
|
-
export type { ErrorHandler } from './onError';
|
|
1
|
+
export { App } from './app.js';
|
|
2
|
+
export type { AppSettings, TemplateEngineOptions, TemplateFunc } from './app.js';
|
|
3
|
+
export * from './request.js';
|
|
4
|
+
import type { Request } from './request.js';
|
|
5
|
+
export * from './response.js';
|
|
6
|
+
import type { Response } from './response.js';
|
|
7
|
+
export { extendMiddleware } from './extend.js';
|
|
8
|
+
export { onErrorHandler } from './onError.js';
|
|
9
|
+
export type { ErrorHandler } from './onError.js';
|
|
10
10
|
import type { NextFunction, Handler as RHandler, AsyncHandler as RAsyncHandler, SyncHandler as RSyncHandler, Middleware } from '@tinyhttp/router';
|
|
11
11
|
export declare type Handler = RHandler<Request, Response>;
|
|
12
12
|
export declare type AsyncHandler = RAsyncHandler<Request, Response>;
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ import { Router, pushMiddleware } from '@tinyhttp/router';
|
|
|
8
8
|
import { getResponseHeader, setHeader, send, json, status, sendStatus, sendFile, setContentType, setLocationHeader, setLinksHeader, setVaryHeader, setCookie, clearCookie, formatResponse, redirect, attachment, download, append } from '@tinyhttp/res';
|
|
9
9
|
import { parse } from 'regexparam';
|
|
10
10
|
|
|
11
|
-
const trustRemoteAddress = ({
|
|
12
|
-
const val =
|
|
11
|
+
const trustRemoteAddress = ({ socket }) => {
|
|
12
|
+
const val = socket.remoteAddress;
|
|
13
13
|
if (typeof val === 'function')
|
|
14
14
|
return val;
|
|
15
15
|
if (typeof val === 'boolean' && val === true)
|
|
@@ -169,7 +169,7 @@ class App extends Router {
|
|
|
169
169
|
this.engines = {};
|
|
170
170
|
this.onError = (options === null || options === void 0 ? void 0 : options.onError) || onErrorHandler;
|
|
171
171
|
this.noMatchHandler = (options === null || options === void 0 ? void 0 : options.noMatchHandler) || this.onError.bind(null, { code: 404 });
|
|
172
|
-
this.settings = options.settings || { xPoweredBy: true };
|
|
172
|
+
this.settings = options.settings || { xPoweredBy: true, views: process.cwd() };
|
|
173
173
|
this.applyExtensions = options === null || options === void 0 ? void 0 : options.applyExtensions;
|
|
174
174
|
this.attach = (req, res) => setImmediate(this.handler.bind(this, req, res, undefined), req, res);
|
|
175
175
|
}
|
|
@@ -206,7 +206,7 @@ class App extends Router {
|
|
|
206
206
|
* @param cb Callback that consumes error and html
|
|
207
207
|
*/
|
|
208
208
|
render(file, data = {}, cb, options = {}) {
|
|
209
|
-
options.viewsFolder = options.viewsFolder || `${process.cwd()}/views`;
|
|
209
|
+
options.viewsFolder = options.viewsFolder || this.settings.views || `${process.cwd()}/views`;
|
|
210
210
|
options.ext = options.ext || file.slice(file.lastIndexOf('.') + 1) || 'ejs';
|
|
211
211
|
options._locals = options._locals || {};
|
|
212
212
|
options.cache = options.cache || process.env.NODE_ENV === 'production';
|
package/dist/onError.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextFunction } from '@tinyhttp/router';
|
|
2
|
-
import type { Request } from './request';
|
|
3
|
-
import type { Response } from './response';
|
|
2
|
+
import type { Request } from './request.js';
|
|
3
|
+
import type { Response } from './response.js';
|
|
4
4
|
export declare type ErrorHandler = (err: any, req: Request, res: Response, next?: NextFunction) => void;
|
|
5
5
|
export declare const onErrorHandler: ErrorHandler;
|
package/dist/request.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
2
5
|
import { IncomingMessage } from 'http';
|
|
3
6
|
import { ParsedUrlQuery } from 'querystring';
|
|
4
7
|
import { Options, Ranges } from 'header-range-parser';
|
|
5
|
-
import { App } from './app';
|
|
8
|
+
import { App } from './app.js';
|
|
6
9
|
import type { Middleware, Handler } from '@tinyhttp/router';
|
|
7
|
-
import type { Response } from './response';
|
|
10
|
+
import type { Response } from './response.js';
|
|
8
11
|
import type { URLParams } from '@tinyhttp/req';
|
|
12
|
+
import type { Socket } from 'net';
|
|
13
|
+
import type { TLSSocket } from 'tls';
|
|
9
14
|
export { getURLParams } from '@tinyhttp/req';
|
|
10
15
|
export declare const getRouteFromApp: ({ middleware }: App, h: Handler<Request, Response>) => Middleware<Request, Response>;
|
|
11
16
|
export declare const getProtocol: (req: Request) => Protocol;
|
|
12
17
|
export declare const getHostname: (req: Request) => string | undefined;
|
|
13
|
-
export declare const getIP: (req: Pick<
|
|
14
|
-
export declare const getIPs: (req: Pick<
|
|
18
|
+
export declare const getIP: (req: Pick<Request, 'headers' | 'connection' | 'socket'>) => string | undefined;
|
|
19
|
+
export declare const getIPs: (req: Pick<Request, 'headers' | 'connection' | 'socket'>) => string[] | undefined;
|
|
15
20
|
export declare const getSubdomains: (req: Request, subdomainOffset?: number) => string[];
|
|
16
21
|
export declare type Connection = IncomingMessage['socket'] & {
|
|
17
22
|
encrypted: boolean;
|
|
@@ -26,6 +31,7 @@ export interface Request extends IncomingMessage {
|
|
|
26
31
|
query: ParsedUrlQuery;
|
|
27
32
|
params: URLParams;
|
|
28
33
|
connection: Connection;
|
|
34
|
+
socket: TLSSocket | Socket;
|
|
29
35
|
route?: Middleware;
|
|
30
36
|
protocol: Protocol;
|
|
31
37
|
secure: boolean;
|
package/dist/response.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ServerResponse } from 'http';
|
|
3
3
|
import type { SerializeOptions } from '@tinyhttp/cookie';
|
|
4
|
-
import { Request } from './request';
|
|
5
|
-
import { App, TemplateEngineOptions } from './app';
|
|
4
|
+
import { Request } from './request.js';
|
|
5
|
+
import { App, TemplateEngineOptions } from './app.js';
|
|
6
6
|
import type { ReadStreamOptions, FormatProps, DownloadOptions } from '@tinyhttp/res';
|
|
7
7
|
export declare const renderTemplate: <O>(_req: Request, res: Response, app: App) => (file: string, data?: Record<string, any>, options?: Partial<{
|
|
8
8
|
cache: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyhttp/app",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.22",
|
|
4
4
|
"description": "0-legacy, tiny & fast web framework as a replacement of Express",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://tinyhttp.v1rtl.site",
|
|
@@ -32,16 +32,15 @@
|
|
|
32
32
|
"author": "v1rtl",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tinyhttp/cookie": "2.0.
|
|
36
|
-
"@tinyhttp/proxy-addr": "2.0.
|
|
37
|
-
"@tinyhttp/req": "2.0.
|
|
38
|
-
"@tinyhttp/res": "2.0.
|
|
39
|
-
"@tinyhttp/router": "2.0.
|
|
35
|
+
"@tinyhttp/cookie": "2.0.4",
|
|
36
|
+
"@tinyhttp/proxy-addr": "2.0.4",
|
|
37
|
+
"@tinyhttp/req": "2.0.13",
|
|
38
|
+
"@tinyhttp/res": "2.0.17",
|
|
39
|
+
"@tinyhttp/router": "2.0.5",
|
|
40
40
|
"header-range-parser": "1.1.3",
|
|
41
41
|
"regexparam": "^2.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "rollup -c"
|
|
45
|
-
}
|
|
46
|
-
"readme": "# @tinyhttp/app\n\nThe core of tinyhttp. Contains the `App`, `Request` and `Response`. Additionally, it provides special tinyhttp-specific types.\n\n## Install\n\n```sh\npnpm i @tinyhttp/app\n```\n\n## Example\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport type { Request, Response, NextFunction } from '@tinyhttp/app'\n\nnew App()\n .use((req: Request, res: Response, next: NextFunction) => {\n console.log('Did a request')\n next()\n })\n .get('/', (_, res) => res.send('<h1>Hello World</h1>'))\n .get('/page/:page', (req, res) => res.send(`You opened ${req.params.page}`))\n .listen(3000)\n```\n"
|
|
45
|
+
}
|
|
47
46
|
}
|