@@ -110,8 +110,8 @@ pub const App = struct {
110
110
logger : Logger ,
111
111
config : std .json .Parsed (Config ),
112
112
db_pool : fr .Pool (fr .SQLite3 ),
113
- llama : llama.Pool ,
114
- client : std.http.Client ,
113
+ llama : llama.Pool , // TODO: extract to standalone module
114
+ client : std.http.Client , // TODO: switch to tk.Client
115
115
server : tk.Server ,
116
116
117
117
const CONFIG_FILE = "config.json" ;
@@ -124,6 +124,27 @@ pub const App = struct {
124
124
inline for (std .meta .fields (Config )) | f | try ct .register (&@field (target .value , f .name ));
125
125
}
126
126
127
+ pub fn initServer (target : * tk.Server , allocator : std.mem.Allocator , cfg : @FieldType (Config , "server" ), injector : * tk .Injector ) ! void {
128
+ target .* = try tk .Server .init (allocator , routes , .{
129
+ .listen = cfg ,
130
+ .injector = injector ,
131
+ });
132
+ }
133
+
134
+ pub fn afterAppInit (allocator : std.mem.Allocator , db_pool : * fr .Pool (fr.SQLite3 ), client : * std .http .Client ) ! void {
135
+ var db = try db_pool .getSession (allocator );
136
+ defer db .deinit ();
137
+
138
+ try fr .migrate (db , @embedFile ("db_schema.sql" ));
139
+
140
+ if (comptime builtin .target .os .tag == .windows ) {
141
+ try client .ca_bundle .rescan (allocator );
142
+ const start = client .ca_bundle .bytes .items .len ;
143
+ try client .ca_bundle .bytes .appendSlice (allocator , @embedFile ("amazon1.cer" ));
144
+ try client .ca_bundle .parseCert (allocator , @intCast (start ), std .time .timestamp ());
145
+ }
146
+ }
147
+
127
148
pub fn updateConfig (self : * App , config : Config ) ! void {
128
149
// thread-safety!
129
150
self .mutex .lock ();
@@ -163,24 +184,6 @@ pub const App = struct {
163
184
file .writer (),
164
185
);
165
186
}
166
-
167
- pub fn initClient (target : * std.http.Client , allocator : std.mem.Allocator ) ! void {
168
- target .* = .{ .allocator = allocator };
169
-
170
- if (builtin .target .os .tag == .windows ) {
171
- try target .ca_bundle .rescan (allocator );
172
- const start = target .ca_bundle .bytes .items .len ;
173
- try target .ca_bundle .bytes .appendSlice (allocator , @embedFile ("amazon1.cer" ));
174
- try target .ca_bundle .parseCert (allocator , @intCast (start ), std .time .timestamp ());
175
- }
176
- }
177
-
178
- pub fn initServer (target : * tk.Server , allocator : std.mem.Allocator , cfg : @FieldType (Config , "server" ), injector : * tk .Injector ) ! void {
179
- target .* = try tk .Server .init (allocator , routes , .{
180
- .listen = cfg ,
181
- .injector = injector ,
182
- });
183
- }
184
187
};
185
188
186
189
const api : tk.Route = .group ("/api" , &.{
0 commit comments