first commit
This commit is contained in:
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "enter program name, for example ${workspaceFolder}/a.out",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -std=c++17 -Wall -pthread
|
||||
TARGET = backend
|
||||
SRCS = backend.cpp
|
||||
|
||||
all: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(CXX) $(CXXFLAGS) -o $(TARGET) $(SRCS)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
|
||||
.PHONY: all clean
|
||||
31
backend.cpp
Normal file
31
backend.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "crow.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int main() {
|
||||
crow::SimpleApp app;
|
||||
|
||||
CROW_ROUTE(app, "/")([](){
|
||||
auto page = crow::mustache::load_text("index.html");
|
||||
return page;
|
||||
});
|
||||
|
||||
|
||||
CROW_ROUTE(app, "/button").methods("POST"_method)([](const crow::request& req) {
|
||||
auto x = crow::json::load(req.body);
|
||||
if (!x) {
|
||||
return crow::response(400, "invalid JSON");
|
||||
}
|
||||
std::string name = x["name"].s();
|
||||
name.erase(std::remove_if(name.begin(), name.end(), ::isspace), name.end());
|
||||
std::cout << name << std::endl;
|
||||
return crow::response(200, name);
|
||||
});
|
||||
|
||||
app.port(18080).multithreaded().run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
33
compose.yml
Normal file
33
compose.yml
Normal file
@ -0,0 +1,33 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:latest
|
||||
container_name: postgres_latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: duck
|
||||
POSTGRES_PASSWORD: duckpass
|
||||
POSTGRES_DB: duckdb
|
||||
volumes:
|
||||
- db_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4:latest
|
||||
container_name: pgadmin_latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: admin@example.com
|
||||
PGADMIN_DEFAULT_PASSWORD: adminpass
|
||||
volumes:
|
||||
- pgadmin_data:/var/lib/pgadmin
|
||||
ports:
|
||||
- "8080:80"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
pgadmin_data:
|
||||
93
templates/index.html
Normal file
93
templates/index.html
Normal file
@ -0,0 +1,93 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang ="en">
|
||||
<head>
|
||||
|
||||
|
||||
<style>
|
||||
body {
|
||||
background-color: #2B2A34;
|
||||
}
|
||||
.input_field {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.response_container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
max-width: fit-content;
|
||||
margin: 5px auto;
|
||||
|
||||
}
|
||||
.response_text {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
border: 2px solid black;
|
||||
border-radius: 5px;
|
||||
max-width: 300px;
|
||||
margin: 5px auto;
|
||||
background-color: white;
|
||||
width: 200px;
|
||||
height: 20px;
|
||||
}
|
||||
.response_button {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
async function send_input() {
|
||||
const input = document.getElementById('input').value;
|
||||
const res = await fetch('/button', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({name: input})
|
||||
});
|
||||
const data = await res.text();
|
||||
const box = document.getElementById('response_text');
|
||||
box.textContent = data
|
||||
document.getElementById('input').value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
|
||||
<title>javascript test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="input_field">
|
||||
<input type="text" id="input"/>
|
||||
<button onclick = "send_input()"> send </button>
|
||||
<script>
|
||||
const input = document.getElementById('input');
|
||||
input.addEventListener('keydown', function(event) {
|
||||
if (event.code == 'Enter'){
|
||||
send_input();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
<div id="response_container" class="response_container">
|
||||
<div id="response_text" class="response_text"></div>
|
||||
<div class="response_button">
|
||||
<button onclick="copy_to_clipboard()">📋</button>
|
||||
</div>
|
||||
<script>
|
||||
function copy_to_clipboard() {
|
||||
const copyText = document.getElementById('response_text').textContent;
|
||||
console.log(copyText);
|
||||
|
||||
navigator.clipboard.writeText(copyText);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user