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
|
|
@ -23,6 +23,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
|
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-groovy-templates'
|
implementation 'org.springframework.boot:spring-boot-starter-groovy-templates'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@ package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
//import org.springframework.boot.SpringApplication;
|
|
||||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
@SpringBootApplication
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
public class ActivityPubBotApplication {
|
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) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ActivityPubBotApplication.class, args);
|
SpringApplication.run(ActivityPubBotApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
@ -32,5 +42,5 @@ public class ActivityPubBotApplication {
|
||||||
System.out.println(beanName);
|
System.out.println(beanName);
|
||||||
}* /
|
}* /
|
||||||
};
|
};
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package dev.activitypub.activitypubbot;
|
package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.
|
* extending this to handle the basic ActivityPub implementation.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@RequestMapping( headers = "accept=application/json" )
|
||||||
public class HomeController {
|
public class HomeController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -20,19 +22,11 @@ public class HomeController {
|
||||||
return apProps.getKeyFilePath();
|
return apProps.getKeyFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Keeping / mysterious...
|
|
||||||
*/
|
|
||||||
@GetMapping("/")
|
|
||||||
public String index() {
|
|
||||||
return "Parsnip!";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Really just an alias to /user/springbot
|
* Really just an alias to /user/springbot
|
||||||
* TODO: how to auto-map @<user> to /users/<user>
|
* TODO: how to auto-map @<user> to /users/<user>
|
||||||
*/
|
*/
|
||||||
@GetMapping("/@springbot")
|
@RequestMapping(value = "/@springbot", headers = "accept=application/json")
|
||||||
public String atactor() {
|
public String atactor() {
|
||||||
return this.actor();
|
return this.actor();
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +35,7 @@ public class HomeController {
|
||||||
* Access the bot/user - ultimately this should check the database for
|
* Access the bot/user - ultimately this should check the database for
|
||||||
* /user/<user> to pull out the relevant data.
|
* /user/<user> to pull out the relevant data.
|
||||||
*/
|
*/
|
||||||
@GetMapping("/users/springbot")
|
@RequestMapping(value = "/users/springbot", headers = "accept=application/json")
|
||||||
public String actor() {
|
public String actor() {
|
||||||
// TODO: this needs some sort of object wrapper or template, and data in database
|
// TODO: this needs some sort of object wrapper or template, and data in database
|
||||||
return """
|
return """
|
||||||
|
|
@ -64,8 +58,27 @@ public class HomeController {
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"id": "https://springbot.seth.id.au/users/springbot#main-key",
|
"id": "https://springbot.seth.id.au/users/springbot#main-key",
|
||||||
"owner": "https://springap.seth.id.au/users/springbot",
|
"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
|
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-type=PKCS12
|
||||||
server.ssl.key-store=classpath:keys/activitypubbot.p12
|
server.ssl.key-store=classpath:keys/activitypubbot.p12
|
||||||
server.ssl.key-store-password=password
|
server.ssl.key-store-password=password
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue