Example Server Setup
Simple WebApp server example with WebSocket support and routing configuration
Simple WebApp Server Example
This example demonstrates how to set up a basic WebApp server with WebSocket support, routing, and email functionality.
Prerequisites
Before you begin, ensure you have:
- Dart SDK
- WebApp package installed (
dart pub add webapp
)
Basic Server Setup
Here's a complete example of setting up a WebApp server:
Import Necessary Packages
Configure Server Settings
Create Server with WebSocket Support
Start the Server
Configuration Options
- widgetsPath: Specifies the directory where frontend widgets are stored
- widgetsType: Defines the file type for widgets (e.g., j2.html templates)
- languagePath: Points to the directory containing language files for internationalization
- port: Sets the port number where the server will listen for requests
- dbConfig: Configures database settings (MongoDB can be enabled/disabled)
- publicDir: Specifies the directory for serving static files
SMTP Email Example
The WebApp package also supports SMTP email functionality:
MySQL Database Example
WebApp 2.0.1 includes powerful MySQL support:
Running the Server
To start the server, run your main Dart file:
Or using the WebApp CLI:
After the server starts, you'll see output like:
Next Steps
- Explore Routing for advanced routing features
- Learn about Controllers for organized code structure
- Check out Database Management for data handling
- See WebSocket for real-time features