Skip to content
Snippets Groups Projects
Commit 496659a3 authored by Pesti Tamás's avatar Pesti Tamás
Browse files

Fix nginx API and CORS rules

parent 58c44db0
Branches
Tags
No related merge requests found
...@@ -10,7 +10,10 @@ public class CorsConfig implements WebMvcConfigurer { ...@@ -10,7 +10,10 @@ public class CorsConfig implements WebMvcConfigurer {
@Override @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") registry.addMapping("/**")
.allowedOrigins("http://localhost/", "https://localhost/", "http://127.0.0.1/", "https://127.0.0.1/", "https://vau-vau.web.app/", "http://localhost:3000", "http://localhost:3001", "http://localhost:3002", "http://localhost:8080") .allowedOrigins(
"https://vau-vau.web.app/", // from Firebase webapp frontend
"http://127.0.0.1:3000/", "http://localhost:3000/", // from nodejs frontend
"http://127.0.0.1/", "http://localhost/") // from nginx frontend
.allowedMethods("*"); .allowedMethods("*");
} }
} }
import axios from 'axios'; export {default as axios} from 'axios';
axios.defaults.baseURL = 'http://localhost:8080'; export const apiURL = 'http://localhost:8080/api'; // local development
// export const apiURL = '/api'; // nginx
export default axios;
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</template> </template>
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
import { mapState } from "vuex"; import { mapState } from "vuex";
export default { export default {
...@@ -35,7 +35,7 @@ export default { ...@@ -35,7 +35,7 @@ export default {
methods: { methods: {
async login() { async login() {
try { try {
const response = await axios.post('/api/login', { const response = await axios.post(apiURL + '/login', {
username: this.username, username: this.username,
password: this.password password: this.password
}); });
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</template> </template>
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
import { ref } from 'vue'; import { ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
...@@ -74,7 +74,7 @@ export default { ...@@ -74,7 +74,7 @@ export default {
const register = async () => { const register = async () => {
try { try {
const response = await axios.post('/api/register', { const response = await axios.post(apiURL + '/register', {
username: username.value, username: username.value,
password: password.value password: password.value
}); });
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</template> </template>
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
export default { export default {
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
const config = { const config = {
headers: { Authorization: `Bearer ${this.token}` }, headers: { Authorization: `Bearer ${this.token}` },
}; };
await axios.post(`/api/newdog`, this.dog, config); await axios.post(apiURL + '/newdog', this.dog, config);
this.$router.push(`/dogs`); this.$router.push(`/dogs`);
}, },
}, },
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
export default { export default {
name: 'AllDogs', name: 'AllDogs',
...@@ -39,7 +39,7 @@ export default { ...@@ -39,7 +39,7 @@ export default {
}, },
async created() { async created() {
try { try {
const response = await axios.get('/api/dogs', {timeout: 5000}); // 5 seconds timeout const response = await axios.get(apiURL + '/dogs', {timeout: 5000}); // 5 seconds timeout
if (response.status === 200) { if (response.status === 200) {
if (response.data && response.data.length > 0) { if (response.data && response.data.length > 0) {
this.dogs = response.data; this.dogs = response.data;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</template> </template>
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import vueFilePond from 'vue-filepond'; import vueFilePond from 'vue-filepond';
import FilePondPluginImagePreview from 'filepond-plugin-image-preview'; import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
...@@ -64,7 +64,7 @@ export default { ...@@ -64,7 +64,7 @@ export default {
console.log('FilePond has initialized'); console.log('FilePond has initialized');
}, },
async fetchDog() { async fetchDog() {
const response = await axios.get(`/api/dogs/${this.$route.params.id}`); const response = await axios.get(apiURL + `/dogs/${this.$route.params.id}`);
this.dog = response.data; this.dog = response.data;
}, },
validateAndEditDog() { validateAndEditDog() {
...@@ -117,7 +117,7 @@ export default { ...@@ -117,7 +117,7 @@ export default {
}; };
try { try {
await axios.post(`/api/dogs/${this.$route.params.id}/edit`, formData, config); await axios.post(apiURL + `/dogs/${this.$route.params.id}/edit`, formData, config);
this.$router.push(`/dog/${this.$route.params.id}`); this.$router.push(`/dog/${this.$route.params.id}`);
} catch (error) { } catch (error) {
console.error('Error editing dog:', error); console.error('Error editing dog:', error);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</template> </template>
<script> <script>
import axios from '@/axiosConfig.js'; import { axios, apiURL } from '@/axiosConfig.js';
export default { export default {
name: 'SingleDog', name: 'SingleDog',
...@@ -23,7 +23,7 @@ export default { ...@@ -23,7 +23,7 @@ export default {
async created() { async created() {
const id = this.$route.params.id; const id = this.$route.params.id;
try { try {
const response = await axios.get(`/api/dogs/${id}`); const response = await axios.get(apiURL + `/dogs/${id}`);
this.dog = response.data; this.dog = response.data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
...@@ -36,7 +36,7 @@ export default { ...@@ -36,7 +36,7 @@ export default {
const config = { const config = {
headers: { Authorization: `Bearer ${this.token}` }, headers: { Authorization: `Bearer ${this.token}` },
}; };
await axios.delete(`/api/dogs/${this.$route.params.id}`, config); await axios.delete(apiURL + `/dogs/${this.$route.params.id}`, config);
this.$router.push(`/dogs`); this.$router.push(`/dogs`);
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment