|
Hello, word!
In this example we show how to:
- setup UnityBase HTTP server for handle static;
- enable HTTP caching;
|
1. Setup UnityBase HTTP server
First of all we create server config ubConfig.json
file:
{
"HTTPServerType": "stHTTPSys",
"logPath": "..\\logs",
"logLevel": ["*"],
"appConfigs": {
"gs": {
"domainName": "gettingStarted",
"staticFolder": ".\\Web\\" /*folder for static. If set application handle static files request */
}
},
"domainConfigs": {
"gettingStarted": {
}
}
}
Here we:
- define empty Domain named
gettingStarted
inside domainConfigs
section
- define Application named
gs
inside appConfig
section
- setup application domain name to empty
gettingStarted
Domain
- set application static folder to
.\Web\
folder
- set logging path to
..\logs
folder and tell UnityBase to log almost anything happens on the server
side by setting logLevel
to ['*']
Now you can run UnityBase by typing in console:
cd Samples\01_Static_HTTP_Server
start ub -c
and follow this link.
You can see static HTML page served by UnityBase HTTP server.
2. Enable HTTP caching
Let's enable HTTP caching for images:
- shut down UnityBase
- define
staticRules
section inside application configuration section
- define single rule: all files with images extensions are valid for one month:
"staticRules": {
"images": {
"location": "\\.(ico|txt|gif|jpg|png|jpeg)$",
"expires": 2592000
}
}
Start server and refresh this page
Take a look to network tab of browser developer tool - img\UBLogo128.png
file now come from cache
3. More info