fix: Update port and improve logging
- Change server port from 8086 to 8080 - Use `console.print_info` for logging instead of `println` - Improve error handling in `decode_generic` - Update JSONRPC imports for consistency - Add `console.print_stderr` for not found methods - Refactor `DBCalendar.list` to remove redundant `println` - Add `console.print_info` for logging fallback - Introduce `print_info` in console module for blue text output
This commit is contained in:
@@ -10,7 +10,7 @@ fn main() {
|
||||
heromodels.new(reset: true, name: 'test')!
|
||||
heromodels.server_start(
|
||||
name: 'test'
|
||||
port: 8086
|
||||
port: 8080
|
||||
auth_enabled: false // Disable auth for testing
|
||||
cors_enabled: true
|
||||
reset: true
|
||||
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.schemas.openrpc
|
||||
import os
|
||||
|
||||
// 1. Create a new server instance
|
||||
mut server := heroserver.new(port: 8086)!
|
||||
mut server := heroserver.new(port: 8080)!
|
||||
|
||||
// 2. Create and register your OpenRPC handlers
|
||||
// These handlers must conform to the `openrpc.OpenRPCHandler` interface.
|
||||
@@ -14,8 +14,8 @@ openrpc_path := os.join_path(script_dir, 'openrpc.json')
|
||||
handler := openrpc.new_handler(openrpc_path)!
|
||||
server.register_handler('comments', handler)!
|
||||
|
||||
println('Server starting on http://localhost:8086')
|
||||
println('Documentation available at: http://localhost:8086/doc/comments/')
|
||||
println('Comments API available at: http://localhost:8086/api/comments')
|
||||
println('Server starting on http://localhost:8080')
|
||||
println('Documentation available at: http://localhost:8080/doc/comments/')
|
||||
println('Comments API available at: http://localhost:8080/api/comments')
|
||||
|
||||
server.start()!
|
||||
|
||||
@@ -3,6 +3,7 @@ module logger
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@[params]
|
||||
pub struct LogItemArgs {
|
||||
@@ -77,10 +78,10 @@ fn (mut l Logger) write_to_console(args LogItemArgs, t ourtime.OurTime) ! {
|
||||
|
||||
for i, line in lines {
|
||||
if i == 0 {
|
||||
println('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
console.print_info('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
} else {
|
||||
// Indent continuation lines
|
||||
println('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
console.print_info('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@ pub fn decode_bool(data string) !bool {
|
||||
}
|
||||
|
||||
pub fn decode_generic[T](data string) !T {
|
||||
mut r := json.decode(T, data) or {
|
||||
println('Failed to decode T: \n***\n${data}\n***\n${err}')
|
||||
println(T{})
|
||||
return error('Failed to decode T: ${data}\n${err}')
|
||||
}
|
||||
mut r := json.decode(T, data) or { return error('Failed to decode T: ${data}\n${err}') }
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ module heromodels
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import freeflowuniverse.herolib.hero.db
|
||||
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
|
||||
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_int, new_response_ok, new_response_true }
|
||||
import freeflowuniverse.herolib.hero.user { UserRef }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import json
|
||||
|
||||
// Calendar represents a collection of events
|
||||
@@ -138,9 +139,7 @@ pub fn (mut self DBCalendar) get(id u32) !Calendar {
|
||||
}
|
||||
|
||||
pub fn (mut self DBCalendar) list() ![]Calendar {
|
||||
r := self.db.list[Calendar]()!.map(self.get(it)!)
|
||||
println(r)
|
||||
return r
|
||||
return self.db.list[Calendar]()!.map(self.get(it)!)
|
||||
}
|
||||
|
||||
pub fn calendar_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
|
||||
@@ -174,8 +173,7 @@ pub fn calendar_handle(mut f ModelsFactory, rpcid int, servercontext map[string]
|
||||
return new_response(req.id, json.encode(res))
|
||||
}
|
||||
else {
|
||||
println('Method not found on calendar: ${method}')
|
||||
$dbg;
|
||||
console.print_stderr('Method not found on calendar: ${method}')
|
||||
return new_error(rpcid,
|
||||
code: 32601
|
||||
message: 'Method ${method} not found on calendar'
|
||||
|
||||
@@ -2,7 +2,7 @@ module heromodels
|
||||
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
|
||||
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_int, new_response_ok, new_response_true }
|
||||
import freeflowuniverse.herolib.hero.user { UserRef }
|
||||
import json
|
||||
import freeflowuniverse.herolib.hero.db
|
||||
@@ -30,7 +30,6 @@ pub mut:
|
||||
is_template bool // not to be shown as real event, serves as placeholder e.g. for planning
|
||||
}
|
||||
|
||||
|
||||
pub struct Attendee {
|
||||
pub mut:
|
||||
user_id u32
|
||||
@@ -76,8 +75,6 @@ pub mut:
|
||||
public bool // everyone can see the file, otherwise only the organizers, attendees
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub struct EventLocation {
|
||||
pub mut:
|
||||
name string
|
||||
@@ -456,7 +453,8 @@ pub fn (mut self DBCalendarEvent) list(args CalendarEventListArg) ![]CalendarEve
|
||||
|
||||
return filtered_events
|
||||
}
|
||||
pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !jsonrpc.Response {
|
||||
|
||||
pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
|
||||
match method {
|
||||
'get' {
|
||||
id := db.decode_u32(params)!
|
||||
|
||||
@@ -102,8 +102,11 @@ pub fn (mut server HeroServer) api_handler(mut ctx Context, handler_type string)
|
||||
return ctx.request_error('Invalid method format, too many dots. ${ctx.req.method}')
|
||||
}
|
||||
}
|
||||
console.print_debug('Handling request: ${request.method} with params: ${request.params}')
|
||||
// $dbg;
|
||||
|
||||
// Log the request
|
||||
server.log(
|
||||
message: 'Handling request: ${request.method} with params: ${request.params}'
|
||||
)
|
||||
|
||||
// Handle the request using the OpenRPC handler
|
||||
response := handler.handle(request) or { return ctx.server_error('Handler error: ${err}') }
|
||||
|
||||
@@ -3,6 +3,7 @@ module heroserver
|
||||
import freeflowuniverse.herolib.crypt.herocrypt
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
import freeflowuniverse.herolib.core.logger
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
import veb
|
||||
|
||||
@@ -59,7 +60,7 @@ pub fn (mut server HeroServer) log(params ServerLogParams) {
|
||||
logtype: params.level
|
||||
) or {
|
||||
// Fallback to console if logging fails
|
||||
println('[${params.cat}] ${params.message}')
|
||||
console.print_info('[${params.cat}] ${params.message}')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,5 +99,16 @@ pub fn print_green(txt string) {
|
||||
c.reset()
|
||||
}
|
||||
|
||||
// Print info in blue color
|
||||
pub fn print_info(txt string) {
|
||||
mut c := get()
|
||||
if c.prev_title || c.prev_item {
|
||||
lf()
|
||||
}
|
||||
txt2 := trim(texttools.indent(txt, ' . '))
|
||||
cprintln(foreground: .blue, text: txt2)
|
||||
c.reset()
|
||||
}
|
||||
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
// console.print_header()
|
||||
|
||||
Reference in New Issue
Block a user