mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Merge pull request #50 from mrozigor/static_dir
Added default "static/<path>" route for any static files
This commit is contained in:
commit
d00ec5e690
@ -1,3 +1,5 @@
|
|||||||
|
//#define CROW_STATIC_DRIECTORY "alternative_directory/"
|
||||||
|
//#define CROW_STATIC_ENDPOINT "/alternative_endpoint/<path>"
|
||||||
#include "crow.h"
|
#include "crow.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -20,3 +22,8 @@ CROW_ROUTE(app, "/")
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// You can also use the `/static` directory and endpoint (the directory needs to have the same path as your executable).
|
||||||
|
/// Any file inside the static directory will have the same path it would in your filesystem.
|
||||||
|
|
||||||
|
/// TO change the static directory or endpoint, use the macros above (replace `alternative_directory` and/or `alternative_endpoint` with your own)
|
||||||
|
@ -161,7 +161,16 @@ namespace crow
|
|||||||
///Run the server
|
///Run the server
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
#ifndef CROW_DISABLE_STATIC_DIR
|
||||||
|
route<crow::black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)
|
||||||
|
([](const crow::request&, crow::response& res, std::string file_path_partial)
|
||||||
|
{
|
||||||
|
res.set_static_file_info(CROW_STATIC_DIRECTORY + file_path_partial);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
validate();
|
validate();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CROW_ENABLE_SSL
|
#ifdef CROW_ENABLE_SSL
|
||||||
if (use_ssl_)
|
if (use_ssl_)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,13 @@
|
|||||||
#define CROW_LOG_LEVEL 1
|
#define CROW_LOG_LEVEL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CROW_STATIC_DIRECTORY
|
||||||
|
#define CROW_STATIC_DIRECTORY "static/"
|
||||||
|
#endif
|
||||||
|
#ifndef CROW_STATIC_ENDPOINT
|
||||||
|
#define CROW_STATIC_ENDPOINT "/static/<path>"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// compiler flags
|
// compiler flags
|
||||||
#if __cplusplus >= 201402L
|
#if __cplusplus >= 201402L
|
||||||
|
Loading…
Reference in New Issue
Block a user