Im using nuxt 3 and I'm basing my code off of this documentation: https://stablediffusionapi.com/docs/stable-diffusion-api/text2img/
Im just trying to change this image tag's source into whatever the api gives me. Everything is in vue.js.
<template>
<img id ="hot" @click = "wee()" style = "width:1000px;height:1000px;border:solid;">
</template>
<script>
import axios from 'axios';
function w(){
console.log("dsa");
}
export default {
methods: {
async wee(){
console.log("start");
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Access-Control-Allow-Origin", "*");
myHeaders.append("Access-Control-Allow-Headers", "Content-Type");
myHeaders.append("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
var raw = JSON.stringify({
"key": "THE KEY",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"negative_prompt": null,
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "20",
"seed": null,
"guidance_scale": 7.5,
"safety_checker": "yes",
"multi_lingual": "no",
"panorama": "no",
"self_attention": "no",
"upscale": "no",
"embeddings_model": "embeddings_model_id",
"webhook": null,
"track_id": null
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
var stuff =axios.post("http://stablediffusionapi.com/api/v3/text2img", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
document.getElementById("hot").src = stuff;
}
}
}
</script>
I keep getting this error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://stablediffusionapi.com/api/v3/text2img. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 301.
I tried changing the headers, I changed browsers to chrome, and none of the worked. I'm using firefox, and when I checked thier documentation they said going from https to http is going to cause a CORS error. I tried using the same data on postman.co and it worked just fine. I switched to axios instead of fetch to see if that'd help but it didn't.
Is there a way around this or should i Just give up?