Skip to content
Snippets Groups Projects
Commit 3311b143 authored by Paolo Guagliardo's avatar Paolo Guagliardo
Browse files

Trying to get CORS to work (WIP)

parent 2a8dd0e8
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html lang="en">
<head>
<title>REAL</title>
<meta charset="UTF-8" />
</head>
<body>
<label for="message">Query</label>
<textarea
id="message"
name="message"
rows="5"
cols="33"
></textarea>
<script src="index.js"></script>
</body>
</html>
index.js 0 → 100644
const message = document.getElementById('message');
// ✅ GET the value of textarea
console.log(message.value); // 👉️ ""
// --------------------------------------
// ✅ SET the value of the textarea
message.value = 'Hello world!';
// --------------------------------------
// ✅ Append to the value of textarea
message.value += ' Appended text.';
// --------------------------------------
// ✅ get the value of textarea on change
message.addEventListener('input', function handleChange(event) {
console.log(event.target.value);
});
// Define the API URL
const runQuery = 'http://localhost:8080/run';
const data = {
query: '<P>[A,B]>(<S>[C < 0](R))',
bag: 'false',
};
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
};
// Make a GET request
fetch(runQuery, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
message.value = JSON.stringify(data, null, 2);
})
.catch(error => {
console.error('Error:', error);
});
......@@ -3,13 +3,16 @@ package uk.ac.ed.pguaglia.real.runtime;
import org.antlr.v4.runtime.RecognitionException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ed.pguaglia.real.lang.Expression;
import uk.ac.ed.pguaglia.real.lang.ReplacementException;
@CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
@SpringBootApplication
@RestController
public class WebApp {
......@@ -18,7 +21,7 @@ public class WebApp {
SpringApplication.run(WebApp.class, args);
}
@GetMapping("/run")
@RequestMapping(method = RequestMethod.GET, path = "/{id}")
public String run(
@RequestParam("query") String query,
@RequestParam(name = "bag", required = false, defaultValue = "false") boolean bag) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment