HTTP Server
Overview
The HTTP server serves as the entry point for Diarkis. The application server connects to the HTTP server to obtain real-time connection endpoints and encryption keys.
Additionally, it is possible to define custom endpoints.
Setting up the HTTP Server
To expose built-in commands to the client, you can set up using the diarkisexec
package.
Use
diarkisexec.SetupDiarkis()
to specify modules and expose built-in commands. You can customize settings by specifying theConfigPath
for each module.Use
diarkisexec.SetServerCommandHandler()
to expose custom commands.Use
diarkisexec.SetupDiarkisHTTPServer()
to set up a UDP server. You can customize server settings with a JSON file as an argument.
⚠️ The above functions must be executed before calling
diarkisexec.StartDiarkis()
.
For more details, refer to the API reference of diarkisexec.
Mesh Configuration
Specify the path to the JSON file in meshConfigPath
. For further details, please refer to #mesh-she-ding.
HTTP Server Configuration
The configuration is written in JSON format.
address
"127.0.0.1"
Address for binding the UDP server
port
"7000"
Port for the UDP server to bind. The UDP server will automatically find an available port starting from the specified port.
useFixedPort
false
If true, the HTTP server will only bind to the specified port
timeout
5
HTTP response timeout (in seconds)
enableEncryption
true
If set to false, packet encryption and decryption will be disabled. Other servers must also be configured similarly.
For more details, please refer to the API reference of HTTP.
Creating Custom HTTP Endpoints
The HTTP server in Diarkis allows you to write custom endpoints.
HTTP endpoints with JSON
Diarkis's HTTP server will automatically decode the request body into req.JSONBody
if the request content type is application/json
. Note that the JSON body must describe an object in order to work.
Last updated