Setup the initial structure of the project
This commit is contained in:
commit
1803bc8a0d
|
@ -0,0 +1,4 @@
|
|||
/build/
|
||||
/sources.txt
|
||||
/cobweb.jar
|
||||
.DS_Store
|
|
@ -0,0 +1 @@
|
|||
Main-Class: cobweb.Cobweb
|
|
@ -0,0 +1,7 @@
|
|||
build:
|
||||
find src -type f -name '*.java' > sources.txt
|
||||
javac -d build @sources.txt
|
||||
jar cmf META-INF/MANIFEST.MF cobweb.jar -C build .
|
||||
|
||||
clean:
|
||||
rm -rf build sources.txt cobweb.jar
|
|
@ -0,0 +1,30 @@
|
|||
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) {
|
||||
CobwebServer srv = new CobwebServer(PORT, HOST);
|
||||
|
||||
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.on("get", "/redirect", HttpPermanentRedirect("https://www.example.com"));
|
||||
|
||||
srv.on("get", "/*", WwwDir(WWW_DIR, [
|
||||
AllowTrailingSlash,
|
||||
AllowImpliedIndex,
|
||||
AllowDirectoryListing
|
||||
]));
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public class CobwebServer {
|
||||
public CobwebServer(int port, byte[] host) {
|
||||
System.out.println("Hello, constructor!");
|
||||
}
|
||||
|
||||
public void on(String get, String path, HttpRequestFunction fn) {
|
||||
System.out.println("Hello, on!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public class HttpRequest {
|
||||
public String[] params;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public interface HttpRequestFunction {
|
||||
HttpResponse process(HttpRequest req);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public class HttpResponse {
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public class HttpStaticResponse extends HttpResponse {
|
||||
public HttpStaticResponse(String text) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue