Paul Melero
Web Developer
@paul_melero
Paul Melero
Web Developer
Agriculture Eng. ๐ต
F5
F5
F5
F5
Managed by 3rd parties
VPS, Containers...
us-east1-b
us-east1-b
V8 isolates (secure)
Netlify Edge Functions
Akamai Workers
Cloudflare Workers
Layer0
Closest Point of Presence (POP)ย
import { IpApiResponse } from '~~/types';
export default defineEventHandler(async () => {
const key = useRuntimeConfig().API_TOKEN;
const data: IpApiResponse = await $fetch(
`https://pro.ip-api.com/json/?key=${key}`
);
return data;
});
/server/api/location.ts
import type { Ref } from 'vue';
import type { IpApiResponse } from '@/types';
export const useLocation = () => {
const location: Ref<IpApiResponse> = ref();
watchEffect(async () => {
location.value = await $fetch(`/api/location`);
});
return location;
};
/composables/location.ts
<script setup lang="ts">
// Location
const location = useLocation();
</script>
/app.vue
name = "nuxt-edge-test"
type = "javascript"
account_id = "81bb9e915adce027f7f72b700da03532"
workers_dev = true
route = ""
zone_id = ""
compatibility_date = "2022-04-07"
[site]
bucket = ".output/public"
entry-point = ".output"
[build]
command = ""
[build.upload]
format = "service-worker"
/wrangler.toml
import type { Ref } from 'vue';
export const useLang: () => Ref<string> = () => {
if (process.client) {
return ref(navigator.language);
}
const parseLangString: (languages: string) => string = (languages) => {
return languages.split(',')[0];
};
const nuxt = useNuxtApp();
const lang: string = parseLangString(
nuxt.ssrContext.event.req.headers['accept-language']
);
return ref(lang);
};
/composables/lang.ts
By Paul Melero
Making your application be served from the edge of the cloud is easier thanks to Nuxt DX.