Как вызвать html-страницу в azure function?
Как вызвать html-страницу в azure function?
В чистом Spring Boot проекте у меня она вызывается так.
Java-класс:
@Controller
public class RestController {
final CompareController compareController;
public RestController(CompareController compareController) {
this.compareController = compareController;
}
@GetMapping("/")
public String index() {
return "main";
}
@ResponseBody
@PostMapping(value = "api/v1/compare")
public CompareResults uploadFile(@RequestParam MultipartFile file1, @RequestParam MultipartFile file2,
HttpServletResponse response) throws Exception {
response.setContentType("text/html;charset=UTF-8");
return compareController.compare(extractText(file1.getInputStream()), extractText(file2.getInputStream()));
}
}
HTML-страница:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Text compare</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap" rel="stylesheet">
</head>
<body>
<div>
<h1>Compare text files</h1>
<hr/>
<h4>Upload two files to start.</h4>
<form method="POST" th:action="@{/api/v1/compare}" enctype="multipart/form-data">
<label>original file</label><br/>
<input type="file" name="file1" accept=".txt, .csv, .xaml, .xml,
.c, .cpp, .cs, .java, .py, .groovy, .html, .js, .css" /><br/><br/>
<label class="gc1-4 grow5 fs100">modified file</label><br/>
<input type="file" name="file2" accept=".txt, .csv, .xaml, .xml,
.c, .cpp, .cs, .java, .py, .groovy, .html, .js, .css" />
<hr/>
<button type="submit">Compare files</button>
</form>
</div>
</body>
</html>
А как вызвать html-страницу в Azure Function не могу понять.
Пробовала через Http trigger:
public class MainFunction {
@FunctionName("mainpage")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");
FileCompare fileCompare = new FileCompare();
CompareController compareController = new CompareController(fileCompare);
RestController restController = new RestController(compareController);
return request.createResponseBuilder(HttpStatus.OK).body(restController.index()).build();
}
}
При запуске функция отображает название html файла.
Можете, пожалуйста, подсказать, как вызвать html-страницу в azure function и возможно ли это?