@@ -51,7 +51,7 @@ use storage::ObjectStorage;
51
51
// Global configurations
52
52
const MAX_EVENT_PAYLOAD_SIZE : usize = 102400 ;
53
53
const API_BASE_PATH : & str = "/api" ;
54
- const API_VERSION : & str = "/ v1" ;
54
+ const API_VERSION : & str = "v1" ;
55
55
56
56
#[ actix_web:: main]
57
57
async fn main ( ) -> anyhow:: Result < ( ) > {
@@ -118,8 +118,7 @@ async fn run_http() -> anyhow::Result<()> {
118
118
( _, _) => None ,
119
119
} ;
120
120
121
- let http_server =
122
- HttpServer :: new ( move || create_app ! ( ) . wrap ( HttpAuthentication :: basic ( validator) ) ) ;
121
+ let http_server = HttpServer :: new ( move || create_app ! ( ) ) ;
123
122
if let Some ( builder) = ssl_acceptor {
124
123
http_server
125
124
. bind_openssl ( & CONFIG . parseable . address , builder) ?
@@ -135,40 +134,46 @@ async fn run_http() -> anyhow::Result<()> {
135
134
pub fn configure_routes ( cfg : & mut web:: ServiceConfig ) {
136
135
let generated = generate ( ) ;
137
136
138
- // Base path "{url}/api/v1"
139
- // POST "/query" ==> Get results of the SQL query passed in request body
140
- cfg. service ( web:: resource ( query_path ( ) ) . route ( web:: post ( ) . to ( handlers:: event:: query) ) )
141
- . service (
142
- // logstream API
143
- web:: resource ( logstream_path ( "{logstream}" ) )
144
- // PUT "/logstream/{logstream}" ==> Create log stream
145
- . route ( web:: put ( ) . to ( handlers:: logstream:: put) )
146
- // POST "/logstream/{logstream}" ==> Post logs to given log stream
147
- . route ( web:: post ( ) . to ( handlers:: event:: post_event) )
148
- // DELETE "/logstream/{logstream}" ==> Delete log stream
149
- . route ( web:: delete ( ) . to ( handlers:: logstream:: delete) )
150
- . app_data ( web:: JsonConfig :: default ( ) . limit ( MAX_EVENT_PAYLOAD_SIZE ) ) ,
151
- )
152
- . service (
153
- web:: resource ( alert_path ( "{logstream}" ) )
154
- // PUT "/logstream/{logstream}/alert" ==> Set alert for given log stream
155
- . route ( web:: put ( ) . to ( handlers:: logstream:: put_alert) )
156
- // GET "/logstream/{logstream}/alert" ==> Get alert for given log stream
157
- . route ( web:: get ( ) . to ( handlers:: logstream:: get_alert) ) ,
158
- )
159
- // GET "/logstream" ==> Get list of all Log Streams on the server
160
- . service ( web:: resource ( logstream_path ( "" ) ) . route ( web:: get ( ) . to ( handlers:: logstream:: list) ) )
161
- . service (
162
- // GET "/logstream/{logstream}/schema" ==> Get schema for given log stream
163
- web:: resource ( schema_path ( "{logstream}" ) )
164
- . route ( web:: get ( ) . to ( handlers:: logstream:: schema) ) ,
165
- )
166
- // GET "/liveness" ==> Livenss check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command
167
- . service ( web:: resource ( liveness_path ( ) ) . route ( web:: get ( ) . to ( handlers:: liveness) ) )
168
- // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes
169
- . service ( web:: resource ( readiness_path ( ) ) . route ( web:: get ( ) . to ( handlers:: readiness) ) )
170
- // GET "/" ==> Serve the static frontend directory
171
- . service ( ResourceFiles :: new ( "/" , generated) ) ;
137
+ cfg. service (
138
+ // Base path "{url}/api/v1"
139
+ web:: scope ( & base_path ( ) )
140
+ // POST "/query" ==> Get results of the SQL query passed in request body
141
+ . service ( web:: resource ( query_path ( ) ) . route ( web:: post ( ) . to ( handlers:: event:: query) ) )
142
+ . service (
143
+ // logstream API
144
+ web:: resource ( logstream_path ( "{logstream}" ) )
145
+ // PUT "/logstream/{logstream}" ==> Create log stream
146
+ . route ( web:: put ( ) . to ( handlers:: logstream:: put) )
147
+ // POST "/logstream/{logstream}" ==> Post logs to given log stream
148
+ . route ( web:: post ( ) . to ( handlers:: event:: post_event) )
149
+ // DELETE "/logstream/{logstream}" ==> Delete log stream
150
+ . route ( web:: delete ( ) . to ( handlers:: logstream:: delete) )
151
+ . app_data ( web:: JsonConfig :: default ( ) . limit ( MAX_EVENT_PAYLOAD_SIZE ) ) ,
152
+ )
153
+ . service (
154
+ web:: resource ( alert_path ( "{logstream}" ) )
155
+ // PUT "/logstream/{logstream}/alert" ==> Set alert for given log stream
156
+ . route ( web:: put ( ) . to ( handlers:: logstream:: put_alert) )
157
+ // GET "/logstream/{logstream}/alert" ==> Get alert for given log stream
158
+ . route ( web:: get ( ) . to ( handlers:: logstream:: get_alert) ) ,
159
+ )
160
+ // GET "/logstream" ==> Get list of all Log Streams on the server
161
+ . service (
162
+ web:: resource ( logstream_path ( "" ) ) . route ( web:: get ( ) . to ( handlers:: logstream:: list) ) ,
163
+ )
164
+ . service (
165
+ // GET "/logstream/{logstream}/schema" ==> Get schema for given log stream
166
+ web:: resource ( schema_path ( "{logstream}" ) )
167
+ . route ( web:: get ( ) . to ( handlers:: logstream:: schema) ) ,
168
+ )
169
+ // GET "/liveness" ==> Livenss check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command
170
+ . service ( web:: resource ( liveness_path ( ) ) . route ( web:: get ( ) . to ( handlers:: liveness) ) )
171
+ // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes
172
+ . service ( web:: resource ( readiness_path ( ) ) . route ( web:: get ( ) . to ( handlers:: readiness) ) )
173
+ . wrap ( HttpAuthentication :: basic ( validator) ) ,
174
+ )
175
+ // GET "/" ==> Serve the static frontend directory
176
+ . service ( ResourceFiles :: new ( "/" , generated) ) ;
172
177
}
173
178
174
179
#[ macro_export]
@@ -188,26 +193,27 @@ macro_rules! create_app {
188
193
}
189
194
190
195
fn base_path ( ) -> String {
191
- format ! ( "{}{}" , API_BASE_PATH , API_VERSION )
196
+ format ! ( "{}/ {}" , API_BASE_PATH , API_VERSION )
192
197
}
193
198
194
199
fn logstream_path ( stream_name : & str ) -> String {
195
200
if stream_name. is_empty ( ) {
196
- return format ! ( "{}/logstream" , base_path( ) ) ;
201
+ "/logstream" . to_string ( )
202
+ } else {
203
+ format ! ( "/logstream/{}" , stream_name)
197
204
}
198
- format ! ( "{}/logstream/{}" , base_path( ) , stream_name)
199
205
}
200
206
201
207
fn readiness_path ( ) -> String {
202
- format ! ( "{} /readiness", base_path ( ) )
208
+ " /readiness". to_string ( )
203
209
}
204
210
205
211
fn liveness_path ( ) -> String {
206
- format ! ( "{} /liveness", base_path ( ) )
212
+ " /liveness". to_string ( )
207
213
}
208
214
209
215
fn query_path ( ) -> String {
210
- format ! ( "{} /query", base_path ( ) )
216
+ " /query". to_string ( )
211
217
}
212
218
213
219
fn alert_path ( stream_name : & str ) -> String {
0 commit comments