This repository was archived by the owner on Jan 23, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include " ../Barcode/BarcodeFactory.h"
4+ #include " ../Barcode/IBarcodeGenerator.h"
35#include " INetworkServer.h"
46#include " crow_all.h"
57
Original file line number Diff line number Diff line change 11#include " ../../include/Network/CrowNetworkServer.h"
22
3- void CrowNetworkServer::configure (int port) { port_ = port; }
3+ void CrowNetworkServer::configure (int port) {
4+ port_ = port;
5+
6+ CROW_ROUTE (app_, " /barcode" )([](const crow::request &req) {
7+ auto type = req.url_params .get (" type" );
8+ auto text = req.url_params .get (" text" );
9+ auto margin = req.url_params .get (" margin" );
10+ auto size = req.url_params .get (" size" );
11+ std::unique_ptr<IBarcodeGenerator> generator = BarcodeFactory::create (type);
12+
13+ std::string matrix;
14+ crow::response resp;
15+ try {
16+ matrix = generator->generate (text, std::stoi (margin), std::stoi (size));
17+
18+ resp.code = 200 ;
19+ resp.add_header (" Content-Type" , " image/svg+xml" );
20+ resp.body = std::move (matrix);
21+ } catch (const std::invalid_argument &ex) {
22+ std::cerr << ex.what () << std::endl;
23+ resp.code = 400 ;
24+ resp.add_header (" Content-Type" , " text/html" );
25+ resp.body = std::move (matrix);
26+ }
27+
28+ return resp;
29+ });
30+ }
431
532void CrowNetworkServer::start () { app_.port (port_).multithreaded ().run (); }
633
Original file line number Diff line number Diff line change @@ -15,29 +15,5 @@ int main() {
1515 CrowNetworkServer server;
1616 server.configure (50329 );
1717
18- CROW_ROUTE (server.getApp (), " /barcode" )([](const crow::request &req) {
19- auto type = req.url_params .get (" type" );
20- auto text = req.url_params .get (" text" );
21- auto margin = req.url_params .get (" margin" );
22- auto size = req.url_params .get (" size" );
23- std::unique_ptr<IBarcodeGenerator> generator = BarcodeFactory::create (type);
24-
25- std::string matrix;
26- crow::response resp;
27- try {
28- matrix = generator->generate (text, std::stoi (margin), std::stoi (size));
29-
30- resp.code = 200 ;
31- resp.add_header (" Content-Type" , " image/svg+xml" );
32- resp.body = std::move (matrix);
33- } catch (const std::invalid_argument &ex) {
34- std::cerr << ex.what () << std::endl;
35- resp.code = 400 ;
36- resp.add_header (" Content-Type" , " text/html" );
37- resp.body = std::move (matrix);
38- }
39-
40- return resp;
41- });
4218 server.start ();
4319}
You can’t perform that action at this time.
0 commit comments