mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #23945 from dancespiele/roads-server
Add types definitions for roads-server
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// Type definitions for roads-server 1.0
|
||||
// Project: https://github.com/Dashron/roads-server
|
||||
// Definitions by: Francisco Jesus <https://github.com/dancespiele>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Road } from "roads";
|
||||
|
||||
/**
|
||||
* Roads-Server is a simple webserver for setting up and using the roads framework on an HTTP or HTTP 2 server
|
||||
*/
|
||||
export class Server {
|
||||
/**
|
||||
*
|
||||
* @param Roads The Road that handles all the routes
|
||||
* @param error_handler An overwrite to the standard error handler. Accepts a single parameter (the error) and should return a Roads.Response object
|
||||
*/
|
||||
constructor(Roads: Road, error_handler?: (error: any) => any);
|
||||
|
||||
/**
|
||||
* Start the http server. Accepts the same parameters as HttpServer.listen
|
||||
* @param port Port which listen the server
|
||||
* @param handler Execution tasks after start the server
|
||||
*/
|
||||
listen(port: number, handler: () => any): any;
|
||||
}
|
||||
|
||||
export class Http2Server {
|
||||
/**
|
||||
*
|
||||
* @param Roads The Road that handles all the routes
|
||||
*/
|
||||
constructor(Roads: Road);
|
||||
|
||||
/**
|
||||
* Start the http server. Accepts the same parameters as HttpServer.listen
|
||||
* @param port Port which listen the server
|
||||
* @param handler Execution tasks after start the server
|
||||
*/
|
||||
listen(port: number, handler: () => any): any;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Road, Response } from "roads";
|
||||
import { Server, Http2Server } from "roads-server";
|
||||
|
||||
const road = new Road();
|
||||
const server = new Server(road, (error: any) => {
|
||||
switch (error.code) {
|
||||
case 404:
|
||||
return new Response("Not Found", 404);
|
||||
case 405:
|
||||
return new Response("Not Allowed", 405);
|
||||
default:
|
||||
case 500:
|
||||
return new Response(error.message, 500);
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(3000, () => {
|
||||
console.log("Serve is running in the port 3000");
|
||||
});
|
||||
|
||||
const server2 = new Http2Server(road);
|
||||
|
||||
server2.listen(3000, () => {
|
||||
console.log("Serve is running in the port 3000");
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"roads-server-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user