Added initial code.
This commit is contained in:
		
							parent
							
								
									409889d539
								
							
						
					
					
						commit
						1506294de8
					
				| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
.dub
 | 
			
		||||
docs.json
 | 
			
		||||
__dummy.html
 | 
			
		||||
docs/
 | 
			
		||||
/handy-http-starter
 | 
			
		||||
handy-http-starter.so
 | 
			
		||||
handy-http-starter.dylib
 | 
			
		||||
handy-http-starter.dll
 | 
			
		||||
handy-http-starter.a
 | 
			
		||||
handy-http-starter.lib
 | 
			
		||||
handy-http-starter-test-*
 | 
			
		||||
*.exe
 | 
			
		||||
*.pdb
 | 
			
		||||
*.o
 | 
			
		||||
*.obj
 | 
			
		||||
*.lst
 | 
			
		||||
*.a
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
Handy-Http by Andrew Lalis is marked with CC0 1.0 Universal. To view a copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0/
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
{
 | 
			
		||||
	"authors": [
 | 
			
		||||
		"Andrew Lalis"
 | 
			
		||||
	],
 | 
			
		||||
	"copyright": "Copyright © 2025, Andrew Lalis",
 | 
			
		||||
	"dependencies": {
 | 
			
		||||
		"handy-http-primitives": "~>1",
 | 
			
		||||
		"handy-http-transport": "~>1"
 | 
			
		||||
	},
 | 
			
		||||
	"description": "A collection of Handy-HTTP dependencies and common boilerplate code for starting a web server in minutes.",
 | 
			
		||||
	"license": "CC0",
 | 
			
		||||
	"name": "handy-http-starter",
 | 
			
		||||
	"targetType": "library"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
{
 | 
			
		||||
	"fileVersion": 1,
 | 
			
		||||
	"versions": {
 | 
			
		||||
		"handy-http-primitives": "1.0.0",
 | 
			
		||||
		"handy-http-transport": "1.0.2",
 | 
			
		||||
		"photon": "0.10.2",
 | 
			
		||||
		"sharded-map": "2.7.0",
 | 
			
		||||
		"streams": "3.5.0"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
module handy_http_starter;
 | 
			
		||||
 | 
			
		||||
public import handy_http_transport;
 | 
			
		||||
public import handy_http_primitives;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Starts an HTTP server, using the given handler to handle all incoming
 | 
			
		||||
 * requests.
 | 
			
		||||
 * Params:
 | 
			
		||||
 *   handler = The handler to use for requests.
 | 
			
		||||
 *   port = The port to host the server on. Defaults to 8080.
 | 
			
		||||
 */
 | 
			
		||||
void startServer(HttpRequestHandler handler, ushort port = 8080) {
 | 
			
		||||
    HttpTransport tp = new Http1Transport(handler, port);
 | 
			
		||||
    tp.start();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Starts an HTTP server, using the given delegate function to handle all
 | 
			
		||||
 * incoming requests.
 | 
			
		||||
 * Params:
 | 
			
		||||
 *   dg = The handler delegate function.
 | 
			
		||||
 *   port = The port to host the server on. Defaults to 8080.
 | 
			
		||||
 */
 | 
			
		||||
void startServer(
 | 
			
		||||
    void delegate(ref ServerHttpRequest, ref ServerHttpResponse) dg,
 | 
			
		||||
    ushort port = 8080
 | 
			
		||||
) {
 | 
			
		||||
    auto handler = new class HttpRequestHandler {
 | 
			
		||||
        void handle(ref ServerHttpRequest req, ref ServerHttpResponse resp) {
 | 
			
		||||
            dg(req, resp);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    startServer(handler, port);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue