full middleware support
This commit is contained in:
@@ -1,16 +1,26 @@
|
||||
package org.lumijiez;
|
||||
|
||||
import org.lumijiez.core.config.ServerConfig;
|
||||
import org.lumijiez.core.http.HttpServer;
|
||||
import org.lumijiez.core.http.HttpStatus;
|
||||
import org.lumijiez.logging.Logger;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
HttpServer server = new HttpServer(8080);
|
||||
ServerConfig config = new ServerConfig.Builder()
|
||||
.port(8080)
|
||||
.keepAliveTimeout(30000)
|
||||
.build();
|
||||
|
||||
server.GET("/hello", (req, res) -> res.sendResponse(200, "Hello, World!"));
|
||||
HttpServer server = new HttpServer(config);
|
||||
|
||||
server.GET("/goodbye", (req, res) -> res.sendResponse(200, "Goodbye, World!"));
|
||||
server.addMiddleware((req, res, chain) -> {
|
||||
Logger.info("MIDDLEWARE", "Request: " + req.getMethod() + " " + req.getPath());
|
||||
chain.next(req, res);
|
||||
});
|
||||
|
||||
server.POST("/data", (req, res) -> res.sendResponse(200, "Data received"));
|
||||
server.GET("/hello", (req, res) ->
|
||||
res.sendResponse(HttpStatus.OK, "Hello, World!"));
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user