@gudhub/webserver
v2.0.0
Published
## Server and local development modes
Downloads
2
Readme
README
Server and local development modes
You can use this web server in 2 defferent ways. In server mode and in local development mode:
Local development mode
If you creating website with @gudhub/ssg-website-cli, you need to use local development mode. To do this, you need to install this package globally, with command:
npm i @gudhub/webserver -g
Then, after starting website build, you need to start webserver. In another terminal type:
gudhub-web-server
Server must automaticaly start on 777 port. You can pass flags to customize server:
| Flag | Default | Description | |-----------------|-------------|-----------------------------------------------------------------------------------------------------------| | -p 8000 | 7777 | Start server on specified port (8000 in this case) | | -host localhost | 127.0.0.1 | Start server on specified host (localhost in this case). Can be used to start server on local ip address. |
Server mode
In server mode, you need to clone repo with code, install packages, and configure env. In this mode, you can server multiple websites from websites folder.
All documentation bellow will be about Server mode
Routing
For now, you have few ways of how to add new pages/routes to your website.
By creating html files. You can create html in root of your website folder. In this case, route will be the same as file name. Also, you can create folders, and put your html files there. Each folder will have subdirectory in route. For example, if you will create structure like this: website.com/services/consulting.html, this page will be accessible by this url: https://website.com/services/consulting/. Additionally, you can create structure like this: website.com/services/consutling/index.html and will have same result.
By adding route in routes array in comfig.js. You can also add object like this to routes array in config.js
{
route: '/services/consulting/', // Route for accessing page
index: '/whatever/services/consulting.html' // Path to html file, that will be rendered, from root of your website folder
}
By using this example, you will have ability to create dynamic routes. To do this, you must add object like this to routes array.
{
route: '/blog/:category/:article/', // Route for accessing page. Dynamic parts of route should start from :
index: '/whatever/blog/article.html' // Path to html file, that will be rendered, from root of your website folder
}
Value of this dynamic parts will be accessible on server side inside query parameters like this: ?category=services&article=why-consulting-is-so-important
Caching
By default, after first visit of page in production mode, will be generated cache for this page. In future visit, only this cache will be served on request, If you want update cache - you need open page with query parameter mode with value ssr: ?mode=ssr. You will receive fresh generated code. Also, this new code will be saved as cache, replacing the old ones. You can disable caching while developing by simply setting MODE env variable to 'development'.