32 lines
807 B
Java
32 lines
807 B
Java
package cobweb;
|
|
|
|
import com.spookyinternet.cobweb.*;
|
|
|
|
public class Cobweb {
|
|
private static final int PORT = 4815;
|
|
private static final byte[] HOST = { 127, 0, 0, 1 };
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
CobwebServer srv = new CobwebServer(PORT, HOST);
|
|
|
|
srv.inspect("get", "/*", (req) -> {
|
|
System.out.println(req.conn.ip + ":" + req.conn.port + " wants " + req.url());
|
|
});
|
|
|
|
srv.on("get", "/hello/{?name}", (req) -> {
|
|
if(req.params.length > 0) {
|
|
return new HttpStaticResponse("Hello, " + req.params[0] + "!");
|
|
} else {
|
|
return new HttpStaticResponse("Hello, world!");
|
|
}
|
|
});
|
|
|
|
srv.run();
|
|
} catch(Exception err) {
|
|
System.out.println(err.getMessage());
|
|
err.printStackTrace();
|
|
}
|
|
}
|
|
}
|