added CORS
This commit is contained in:
57
source/utils.hpp
Normal file
57
source/utils.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <expected>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <expected>
|
||||
#include "json.hpp"
|
||||
#include "crow.h"
|
||||
|
||||
namespace utils {
|
||||
const std::filesystem::path build_dir = "frontend/build/"; // <-- set your build folder
|
||||
|
||||
std::map<std::string, std::string> parseBody(const std::string& body);
|
||||
|
||||
std::optional<std::string> getBodyName(const std::string& body);
|
||||
|
||||
std::expected<bool, std::string> isLocalPortOpen(uint16_t portno);
|
||||
|
||||
std::string to_id_format(const std::string& s);
|
||||
|
||||
std::string loadFile(const std::string& path);
|
||||
|
||||
std::filesystem::path getDataDir();
|
||||
|
||||
std::string urlDecode(const std::string& str);
|
||||
|
||||
std::string currentTime();
|
||||
|
||||
template<typename T>
|
||||
std::string toJsonArray(const std::vector<T>& data){
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (auto& c : data) {
|
||||
arr.push_back(nlohmann::json(c));
|
||||
}
|
||||
return arr.dump();
|
||||
}
|
||||
|
||||
std::expected<nlohmann::json, std::string> parseJson(const std::string& input);
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::expected<T, std::string> fromJson(const std::string& input) {
|
||||
try {
|
||||
return nlohmann::json::parse(input).get<T>();
|
||||
}
|
||||
catch (const nlohmann::json::exception& e) {
|
||||
return std::unexpected(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
std::string read_file(const std::string& path);
|
||||
crow::response getFile(const std::filesystem::path& file_path);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user