Merge pull request #23945 from dancespiele/roads-server

Add types definitions for roads-server
This commit is contained in:
Benjamin Lichtman
2018-03-01 09:21:51 -08:00
committed by GitHub
4 changed files with 94 additions and 0 deletions
+42
View File
@@ -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;
}
+25
View File
@@ -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");
});
+24
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}