Skip to content

Instantly share code, notes, and snippets.

View Aleix-Marti's full-sized avatar

Aleix Martí Carmona Aleix-Marti

View GitHub Profile
<template>
<div>
<form @submit.prevent="onSubmit">
<label for="location">Localitat:</label>
<input
id="location"
type="text"
v-model="query"
@input="fetchLocations"
placeholder="Cerca localitats..."
<template>
<div id="map" style="height: 500px;"></div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import 'leaflet/dist/leaflet.css';
import L from 'leaflet';
import locations from '@/services/location.js';
@Aleix-Marti
Aleix-Marti / functions.php
Created February 2, 2024 07:52
PWA - Headless WP
// Para evitar problemas de CORS con las peticiones entre dominios distintos
add_action('init', 'handle_preflight');
function handle_preflight() {
$origin = get_http_origin();
if ($origin === 'https://midominio.com') {
header("Access-Control-Allow-Origin: midominio");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Headers: Origin, X-Requested-With, X-WP-Nonce, Content-Type, Accept, Authorization');