now we can serve json or html dependent on the req accept header
This commit is contained in:
parent
8cdbc11d92
commit
961c878cbf
5 changed files with 65 additions and 20 deletions
|
|
@ -2,9 +2,6 @@ package dev.activitypub.activitypubbot;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
//import org.springframework.boot.SpringApplication;
|
||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
|
@ -13,9 +10,22 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ActivityPubBotApplication {
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ActivityPubBotApplication extends SpringBootServletInitializer {
|
||||
|
||||
//comment below if deploying outside web container -->
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(ActivityPubBotApplication.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ActivityPubBotApplication.class);
|
||||
}
|
||||
/*
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ActivityPubBotApplication.class, args);
|
||||
}
|
||||
|
|
@ -26,11 +36,11 @@ public class ActivityPubBotApplication {
|
|||
return args -> {
|
||||
System.out.println("Beany McBeanface");
|
||||
|
||||
/*String[] beanNames = ctx.getBeanDefinitionNames();
|
||||
/* String[] beanNames = ctx.getBeanDefinitionNames();
|
||||
Arrays.sort(beanNames);
|
||||
for (String beanName : beanNames) {
|
||||
System.out.println(beanName);
|
||||
}*/
|
||||
}* /
|
||||
};
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
|
@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
* extending this to handle the basic ActivityPub implementation.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping( headers = "accept=application/json" )
|
||||
public class HomeController {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -20,19 +22,11 @@ public class HomeController {
|
|||
return apProps.getKeyFilePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeping / mysterious...
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "Parsnip!";
|
||||
}
|
||||
|
||||
/**
|
||||
* Really just an alias to /user/springbot
|
||||
* TODO: how to auto-map @<user> to /users/<user>
|
||||
*/
|
||||
@GetMapping("/@springbot")
|
||||
@RequestMapping(value = "/@springbot", headers = "accept=application/json")
|
||||
public String atactor() {
|
||||
return this.actor();
|
||||
}
|
||||
|
|
@ -41,7 +35,7 @@ public class HomeController {
|
|||
* Access the bot/user - ultimately this should check the database for
|
||||
* /user/<user> to pull out the relevant data.
|
||||
*/
|
||||
@GetMapping("/users/springbot")
|
||||
@RequestMapping(value = "/users/springbot", headers = "accept=application/json")
|
||||
public String actor() {
|
||||
// TODO: this needs some sort of object wrapper or template, and data in database
|
||||
return """
|
||||
|
|
@ -64,8 +58,27 @@ public class HomeController {
|
|||
"publicKey": {
|
||||
"id": "https://springbot.seth.id.au/users/springbot#main-key",
|
||||
"owner": "https://springap.seth.id.au/users/springbot",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----"
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0A5W6M6b+3meJAU0/Fki\\nkMSrEZ6EEThAv4NmyCeDlRbmFQWbh5rWtb69TxkGkkiSFNM3sgg+RSW44Ehn10mL\\nTptfk6oSWFnFHw9MPxmwlWm1Xw8zmp2OMUlI82w11PECFdITJw/1HW73JSVQYfFq\\nWo9rD6nI9G3LPpAB16015NJ9hyeMvz5RA9p9UE540q0l5iJD/l7bxCjHglOQInQX\\neCiR2ErzQSVq3AMhBehoP7HuhKjs8swi8dOgjO3sawqxUyv2+lkesFD2rvxCcXRO\\nBkg/Y7nmJSEcqtcmKYQdObPCIt/wCZNAihJz7dwnGKLE2+JJqPZMer9fAj077OkQ\\neQIDAQAB\\n-----END PUBLIC KEY-----"
|
||||
}
|
||||
}""";
|
||||
}
|
||||
|
||||
/**
|
||||
* Webfinger the user...
|
||||
*/
|
||||
@GetMapping("/.well-known/webfinger")
|
||||
public String webfinger() {
|
||||
return """
|
||||
{
|
||||
"subject": "acct:springbot@springbot.seth.id.au",
|
||||
|
||||
"links": [
|
||||
{
|
||||
"rel": "self",
|
||||
"type": "application/activity+json",
|
||||
"href": "https://springbot.seth.id.au/users/springbot"
|
||||
}
|
||||
]
|
||||
}""";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class MvcController {
|
||||
|
||||
@RequestMapping("/@springbot")
|
||||
public String home() {
|
||||
System.out.println("Bottty McBotface...");
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String root() {
|
||||
System.out.println("Going home...");
|
||||
return "index";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
spring.application.name=activitypubbot
|
||||
ap.keyFilePath=doodle.de.do
|
||||
spring.mvc.view.prefix: /WEB-INF/views/
|
||||
spring.mvc.view.suffix: .jsp
|
||||
server.ssl.key-store-type=PKCS12
|
||||
server.ssl.key-store=classpath:keys/activitypubbot.p12
|
||||
server.ssl.key-store-password=password
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue