1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 16:37:45 +00:00

Default port for REST to 80(frontier) and restoring frontier additions to REST

This commit is contained in:
amibu 2017-08-08 13:05:33 +02:00
parent e691d0504a
commit 7fcffb7f0b
5 changed files with 86 additions and 1886 deletions

View file

@ -12,7 +12,7 @@
<!-- Port the world server listens for clients -->
<ZonePort>54992</ZonePort>
<!-- Address to connect to the rest server -->
<RestHost>127.0.0.1:8080</RestHost>
<RestHost>127.0.0.1:80</RestHost>
<!-- Secret for server authentication -->
<ServerSecret>default</ServerSecret>
<!-- Connection settings for the mysql db -->

View file

@ -14,7 +14,7 @@
<!-- Secret used for server auth -->
<ServerSecret>default</ServerSecret>
<!-- Web server port -->
<HttpPort>8080</HttpPort>
<HttpPort>80</HttpPort>
<Mysql>
<Host>127.0.0.1</Host>
<Port>3306</Port>

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -521,6 +521,88 @@ int main()
};
server.resource["^(/frontier-api/ffxivsupport/view/get_init)(.*)"]["GET"] = [&server]( shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request ) {
print_request_info( request );
try
{
auto web_root_path = boost::filesystem::canonical( "web" );
auto path = boost::filesystem::canonical( web_root_path / "news.xml" );
//Check if path is within web_root_path
if( distance( web_root_path.begin(), web_root_path.end() ) > distance( path.begin(), path.end() ) ||
!equal( web_root_path.begin(), web_root_path.end(), path.begin() ) )
throw invalid_argument( "path must be within root path" );
if( !( boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path ) ) )
throw invalid_argument( "file does not exist" );
std::string cache_control, etag;
// Uncomment the following line to enable Cache-Control
// cache_control="Cache-Control: max-age=86400\r\n";
auto ifs = make_shared<ifstream>();
ifs->open( path.string(), ifstream::in | ios::binary | ios::ate );
if( *ifs )
{
auto length = ifs->tellg();
ifs->seekg( 0, ios::beg );
*response << "HTTP/1.1 200 OK\r\n" << cache_control << etag << "Content-Length: " << length << "\r\n\r\n";
default_resource_send( server, response, ifs );
}
else
throw invalid_argument( "could not read file" );
}
catch( exception& e )
{
*response << "HTTP/1.1 500\r\n\r\n";
g_log.error( e.what() );
}
};
server.resource["^(/frontier-api/ffxivsupport/information/get_headline_all)(.*)"]["GET"] = [&server]( shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request ) {
print_request_info( request );
try
{
auto web_root_path = boost::filesystem::canonical( "web" );
auto path = boost::filesystem::canonical( web_root_path / "headlines.xml" );
//Check if path is within web_root_path
if( distance( web_root_path.begin(), web_root_path.end() ) > distance( path.begin(), path.end() ) ||
!equal( web_root_path.begin(), web_root_path.end(), path.begin() ) )
throw invalid_argument( "path must be within root path" );
if( !( boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path ) ) )
throw invalid_argument( "file does not exist" );
std::string cache_control, etag;
// Uncomment the following line to enable Cache-Control
// cache_control="Cache-Control: max-age=86400\r\n";
auto ifs = make_shared<ifstream>();
ifs->open( path.string(), ifstream::in | ios::binary | ios::ate );
if( *ifs )
{
auto length = ifs->tellg();
ifs->seekg( 0, ios::beg );
*response << "HTTP/1.1 200 OK\r\n" << cache_control << etag << "Content-Length: " << length << "\r\n\r\n";
default_resource_send( server, response, ifs );
}
else
throw invalid_argument( "could not read file" );
}
catch( exception& e )
{
*response << "HTTP/1.1 500\r\n\r\n";
g_log.error( e.what() );
}
};
//Default GET-example. If no other matches, this anonymous function will be called.
//Will respond with content in the web/-directory, and its subdirectories.
//Default file: index.html