diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6dc242c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+sneedmc
diff --git a/css.h b/css.h
new file mode 100644
index 0000000..a68bffd
--- /dev/null
+++ b/css.h
@@ -0,0 +1,5 @@
+static const char *BASIC_STYLE =
+"\r\n";
+
diff --git a/index.h b/index.h
new file mode 100644
index 0000000..38b7a33
--- /dev/null
+++ b/index.h
@@ -0,0 +1,19 @@
+static const char *INDEX_HTML =
+"\r\n"
+"\r\n"
+ "
\r\n"
+ "SneedMC\r\n"
+ "%s"
+ "\r\n"
+ "\r\n"
+ "SneedMC
\r\n"
+ "WIP site for SneedMC, written in pure Mongoose.
\r\n"
+ "Links:
\r\n"
+ "Website Source\r\n"
+ "SneedMC\r\n"
+ "asd\r\n"
+ "\r\n"
+ "\r\n"
+ "\r\n"
+"\r\n";
+
diff --git a/index.html b/index.html
deleted file mode 100644
index 46568d8..0000000
--- a/index.html
+++ /dev/null
@@ -1 +0,0 @@
-a:
diff --git a/main.c b/main.c
index e99d8ba..c768c0b 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,10 @@
#include "mongoose.h"
-char *port = "6333";
+#include "index.h"
+#include "css.h"
+
+// sneed in phone number, backwards
+char *port = "33367";
void trim(char *str) {
char *_str = str;
@@ -11,6 +15,17 @@ void trim(char *str) {
memmove(str, _str, len + 1);
}
+bool eq(const char *src, const char *comp, size_t len) {
+ return (strncmp(src, comp, len) == 0);
+}
+
+void redir(struct mg_connection *nc, char *to) {
+ char *loc = malloc(strlen(to) + 14);
+
+ sprintf(loc, "Location: %s\r\n", to);
+ mg_http_reply(nc, 302, loc, to);
+}
+
static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) p;
@@ -49,8 +64,17 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
if (strncmp(hm->method.ptr, "POST", hm->method.len) == 0) {
} else if (strncmp(hm->method.ptr, "GET", hm->method.len) == 0){
- struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve local dir
- mg_http_serve_dir(nc, p, &opts);
+ if (eq(uri, "", 1) || eq(uri, "index.html", 11)) {
+ // allow for dynamic stuff in the future
+ mg_http_reply(nc, 200, "", INDEX_HTML, BASIC_STYLE);
+ } else if (eq(uri, "src", 4)) {
+ redir(nc, "https://github.com/Sneederix/sneedmc.org");
+ } else if (eq(uri, "gh", 3)) {
+ redir(nc, "https://github.com/Sneederix/SneedMC");
+ } else {
+ struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve local dir
+ mg_http_serve_dir(nc, p, &opts);
+ }
} else {
mg_http_reply(nc, 405, "Allow: GET, POST\r\n", "");
}
diff --git a/main.o b/main.o
deleted file mode 100644
index b6fdf08..0000000
Binary files a/main.o and /dev/null differ
diff --git a/mongoose.o b/mongoose.o
deleted file mode 100644
index c9fdb36..0000000
Binary files a/mongoose.o and /dev/null differ
diff --git a/sneedmc b/sneedmc
deleted file mode 100755
index 65faf3b..0000000
Binary files a/sneedmc and /dev/null differ