|
1 | | -# Ruby Hello World Web Server |
| 1 | +# featurevisor-example-ruby |
2 | 2 |
|
3 | | -A simple Ruby web server that demonstrates basic HTTP server concepts with a Hello World response. |
4 | | - |
5 | | -## Features |
6 | | - |
7 | | -- Lightweight HTTP server built with pure Ruby |
8 | | -- Responds with "Hello World" on the root endpoint |
9 | | -- Request logging and error handling |
10 | | -- Graceful shutdown with Ctrl+C |
11 | | - |
12 | | -## Prerequisites |
13 | | - |
14 | | -- Ruby 2.7.0 or higher |
15 | | -- Bundler (for managing dependencies) |
| 3 | +Example Ruby web server that demonstrates how to use Featurevisor SDK. |
16 | 4 |
|
17 | 5 | ## Installation |
18 | 6 |
|
19 | | -1. **Clone or download this repository** |
20 | | - ```bash |
21 | | - git clone <repository-url> |
22 | | - cd featurevisor-example-ruby |
23 | | - ``` |
24 | | - |
25 | | -2. **Install dependencies** |
26 | | - ```bash |
27 | | - bundle install |
28 | | - ``` |
29 | | - |
30 | | - Or use the rake task: |
31 | | - ```bash |
32 | | - rake install |
33 | | - ``` |
34 | | - |
35 | | -## Running the Web Server |
36 | | - |
37 | | -### Method 1: Using Rake (recommended) |
38 | | -```bash |
39 | | -rake run |
40 | | -``` |
41 | | - |
42 | | -### Method 2: Direct Ruby execution |
43 | | -```bash |
44 | | -ruby app.rb |
45 | | -``` |
46 | | - |
47 | | -### Method 3: Start in background |
48 | | -```bash |
49 | | -rake start |
50 | | -``` |
51 | | - |
52 | | -### Method 4: Make the file executable and run |
53 | | -```bash |
54 | | -chmod +x app.rb |
55 | | -./app.rb |
56 | | -``` |
57 | | - |
58 | | -## Accessing the Server |
59 | | - |
60 | | -Once the server is running, you can access it at: |
61 | | - |
62 | | -- **Main endpoint**: http://localhost:3000 |
63 | | - |
64 | | -## API Endpoints |
65 | | - |
66 | | -### GET / |
67 | | -Returns a simple "Hello World" text response. |
68 | | - |
69 | | -**Response:** |
70 | | -``` |
71 | | -HTTP/1.1 200 OK |
72 | | -Content-Type: text/plain |
73 | | -Content-Length: 11 |
74 | | -
|
75 | | -Hello World |
76 | | -``` |
77 | | - |
78 | | -## Stopping the Server |
79 | | - |
80 | | -- **If running in foreground**: Press `Ctrl+C` |
81 | | -- **If running in background**: Use `rake stop` |
82 | | - |
83 | | -## Available Rake Tasks |
84 | | - |
85 | | -- `rake run` - Start the web server in foreground |
86 | | -- `rake start` - Start the web server in background |
87 | | -- `rake stop` - Stop the background web server |
88 | | -- `rake check_port` - Check if port 3000 is available |
89 | | -- `rake install` - Install gem dependencies |
90 | | -- `rake lint` - Run RuboCop for code style checking |
91 | | -- `rake clean` - Clean temporary files |
92 | | - |
93 | | -## Project Structure |
| 7 | +Clone the repository, and run: |
94 | 8 |
|
95 | 9 | ``` |
96 | | -featurevisor-example-ruby/ |
97 | | -├── app.rb # Main web server application |
98 | | -├── Gemfile # Ruby dependencies |
99 | | -├── Rakefile # Build tasks |
100 | | -├── .gitignore # Git ignore patterns |
101 | | -├── .editorconfig # Editor configuration |
102 | | -├── .ruby-version # Ruby version specification |
103 | | -├── .rubocop.yml # RuboCop configuration |
104 | | -└── README.md # This file |
| 10 | +$ bundle install |
105 | 11 | ``` |
106 | 12 |
|
107 | | -## Development |
108 | | - |
109 | | -### Code Style |
110 | | -This project uses RuboCop for code style enforcement. Run it with: |
111 | | -```bash |
112 | | -bundle exec rubocop |
113 | | -``` |
| 13 | +## Usage |
114 | 14 |
|
115 | | -### Port Configuration |
116 | | -The server runs on port 3000 by default. You can change this by modifying the port number in `app.rb` or by creating a new instance with a different port. |
| 15 | +Run the server locally, running: |
117 | 16 |
|
118 | | -## Troubleshooting |
119 | | - |
120 | | -### Port already in use |
121 | | -If you get an "Address already in use" error, check if port 3000 is available: |
122 | | -```bash |
123 | | -rake check_port |
124 | 17 | ``` |
125 | | - |
126 | | -### Ruby not found |
127 | | -If you get a "ruby: command not found" error, make sure Ruby is installed and in your PATH. |
128 | | - |
129 | | -### Bundler not found |
130 | | -Install Bundler with: |
131 | | -```bash |
132 | | -gem install bundler |
133 | | -``` |
134 | | - |
135 | | -### Permission denied |
136 | | -If you get a permission error when running `./app.rb`, make sure the file is executable: |
137 | | -```bash |
138 | | -chmod +x app.rb |
139 | | -``` |
140 | | - |
141 | | -## Example Usage |
142 | | - |
143 | | -### Starting the server: |
144 | | -```bash |
145 | 18 | $ rake run |
146 | | -Starting Ruby Hello World Web Server... |
147 | | -Starting Hello World Web Server on port 3000... |
148 | | -Visit http://localhost:3000 in your browser |
149 | | -Press Ctrl+C to stop the server |
150 | | - |
151 | | -2024-01-15 10:30:00 - GET / |
152 | | -2024-01-15 10:30:05 - GET / |
153 | 19 | ``` |
154 | 20 |
|
155 | | -### Testing with curl: |
156 | | -```bash |
157 | | -# Test main endpoint |
158 | | -curl http://localhost:3000/ |
159 | | -# Output: Hello World |
160 | | -``` |
161 | | - |
162 | | -## Contributing |
163 | | - |
164 | | -Feel free to modify this basic template to suit your needs. This is a starting point for learning Ruby web development or building more complex web applications. |
| 21 | +Open your browser and navigate to `http://localhost:3000`. |
165 | 22 |
|
166 | | -## License |
| 23 | +## Featurevisor project |
167 | 24 |
|
168 | | -This project is open source and available under the [MIT License](LICENSE). |
| 25 | +Uses this Featurevisor project to fetch the configuration from: https://github.com/featurevisor/featurevisor-example-cloudflare |
0 commit comments