fix: assume server runs in working directory
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
97ed770166
commit
425695596b
3 changed files with 9 additions and 10 deletions
13
src/main.cpp
13
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, "/<string>")
|
||||
.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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue