Repository navigation
Expand file tree
/
Copy pathApiService.java
More file actions
76 lines (58 loc) · 2.12 KB
/
Copy pathApiService.java
File metadata and controls
76 lines (58 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package nu.marginalia.api;
import com.google.inject.Inject;
import io.jooby.*;
import io.jooby.handler.Cors;
import io.jooby.handler.CorsHandler;
import nu.marginalia.api.svc.LicenseService;
import nu.marginalia.api.svc.ResponseCache;
import nu.marginalia.service.client.ServiceNotAvailableException;
import nu.marginalia.service.discovery.property.ServicePartition;
import nu.marginalia.service.server.BaseServiceParams;
import nu.marginalia.service.server.JoobyService;
import nu.marginalia.service.server.mq.MqRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class ApiService extends JoobyService {
private final ResponseCache responseCache;
private final LicenseService licenseService;
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ApiV1 apiV1;
private final ApiV2 apiV2;
@Inject
public ApiService(BaseServiceParams params,
ResponseCache responseCache,
LicenseService licenseService,
ApiV1 apiV1,
ApiV2 apiV2
)
throws Exception
{
super(params,
List.of(),
List.of()
);
this.responseCache = responseCache;
this.licenseService = licenseService;
this.apiV1 = apiV1;
this.apiV2 = apiV2;
}
@Override
public void startJooby(Jooby jooby) {
super.startJooby(jooby);
jooby.setSessionStore(SessionStore.memory(Cookie.session("marginalia-session")));
jooby.errorCode(ServiceNotAvailableException.class, StatusCode.BAD_GATEWAY);
jooby.use(new CorsHandler(new Cors()
.setOrigin("*")
.setHeaders("API-Key", "X-Requested-With", "Content-Type", "Accept", "Origin")
.setMethods("GET", "POST")));
jooby.install(apiV1);
jooby.install(apiV2);
}
@MqRequest(endpoint = "FLUSH_CACHES")
public void flushCaches(String unusedArg) {
logger.info("Flushing caches");
responseCache.flush();
licenseService.flushCache();
}
}