diff --git a/.gitignore b/.gitignore index ddb00c0..1537245 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/ compile_commands.json + +# Data files lander.data -data/ +pastes/ diff --git a/Dockerfile b/Dockerfile index 42f969b..b430e4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,8 +26,6 @@ RUN make prod && \ FROM alpine:3.16.3 -ENV LANDER_DATA_DIR=/data - RUN apk add --update --no-cache boost && \ mkdir /data && \ chown -R 1000:1000 /data diff --git a/src/main.cpp b/src/main.cpp index 6c45326..a02da25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,12 +27,11 @@ int main() { ENV(api_key, "LANDER_API_KEY"); ENV(base_url, "LANDER_BASE_URL"); - ENV(data_dir, "LANDER_DATA_DIR"); // Initialize trie and populate from data file TernaryTrie *trie = ternarytrie_init(); - std::string file_path = data_dir + "/lander.data"; + std::string file_path = "lander.data"; std::cout << "Populating trie from file '" << file_path << "'..." << std::endl; @@ -49,7 +48,7 @@ int main() { // Create pastes directory if not present // TODO don't just ignore errors here - mkdir((data_dir + "/pastes").c_str(), 0700); + mkdir("pastes", 0700); crow::SimpleApp app; app.loglevel(crow::LogLevel::Info); @@ -57,14 +56,14 @@ int main() { // Serve an entry CROW_ROUTE(app, "/") .methods(crow::HTTPMethod::Get)( - [data_dir, trie](crow::response &res, std::string key) { + [trie](crow::response &res, std::string key) { Entry *entry = ternarytrie_search(trie, key.c_str()); if (entry != NULL) { if (entry->type == Redirect) { res.redirect(entry->string); } else if (entry->type == Paste) { - res.set_static_file_info(data_dir + "/pastes/" + key); + res.set_static_file_info("pastes/" + key); } } else { res.code = 404; @@ -112,7 +111,7 @@ int main() { // Add a new Paste with a randomly generated key CROW_ROUTE(app, "/p/") .methods(crow::HTTPMethod::Post)( - [api_key, base_url, data_dir, trie](const crow::request &req) { + [api_key, base_url, trie](const crow::request &req) { AUTH(); Entry *new_entry = entry_new(Paste, ""); @@ -124,7 +123,7 @@ int main() { // Write paste contents to file std::fstream file; - file.open(data_dir + "/pastes/" + key, std::ios_base::out); + file.open(std::string("pastes/") + key, std::ios_base::out); if (!file.is_open()) { return crow::response(crow::status::INTERNAL_SERVER_ERROR);