Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create backend endpoint #15

Merged
merged 17 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
CMakeUserPresets.json
7 changes: 7 additions & 0 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.27)
project(backend)

find_package(Crow REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} Crow::Crow)
24 changes: 24 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Backend

## Configuration

In `/backend`, install conan:

```bash
brew install conan cmake
conan install . --output-folder=build --build=missing
```

Set up the `/build/` folder:

```bash
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
```

From `/backend`, start the server:

```bash
cd build && ./backend
```
12 changes: 12 additions & 0 deletions backend/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from conan import ConanFile


class BackendRecipe(ConanFile):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: yum!

settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"

def requirements(self):
self.requires("crowcpp-crow/1.0+5")

def build_requirements(self):
self.tool_requires("cmake/3.22.6")
20 changes: 20 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "crow.h"

int main(void) {
// delcare crow application
crow::SimpleApp app;

// define endpoint at the root directory
CROW_ROUTE(app, "/")([](){
crow::json::wvalue response;
response["status"] = "success";
return response;
});

// set the port, set the app to run on multiple threads, and run the app
app.port(18080).multithreaded().run();
}