Setup the initial structure of the project

This commit is contained in:
Nick Chambers 2024-04-13 23:11:56 -05:00
commit 1803bc8a0d
10 changed files with 77 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/build/
/sources.txt
/cobweb.jar
.DS_Store

1
META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1 @@
Main-Class: cobweb.Cobweb

7
Makefile Normal file
View File

@ -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

3
Readme.md Normal file
View File

@ -0,0 +1,3 @@
# Cobweb
Serves web.

30
src/Cobweb.java Normal file
View File

@ -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
]));
*/
}
}

View File

@ -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!");
}
}

View File

@ -0,0 +1,5 @@
package com.spookyinternet.cobweb;
public class HttpRequest {
public String[] params;
}

View File

@ -0,0 +1,5 @@
package com.spookyinternet.cobweb;
public interface HttpRequestFunction {
HttpResponse process(HttpRequest req);
}

View File

@ -0,0 +1,5 @@
package com.spookyinternet.cobweb;
public class HttpResponse {
}

View File

@ -0,0 +1,6 @@
package com.spookyinternet.cobweb;
public class HttpStaticResponse extends HttpResponse {
public HttpStaticResponse(String text) {
}
}