Nuxt3 개발환경설정
https://nuxt.com/docs/getting-started/installation
Installation · Get Started with Nuxt
Get started with Nuxt quickly with our online starters or start locally with your terminal. You can start playing with Nuxt 3 in your browser using our online sandboxes: Play on StackBlitzPlay on CodeSandbox Start with one of our starters and themes direct
nuxt.com
튜토리얼을 따라서 잘 한다면..

Welcome to Nuxt를 확인할수 있음.
내 경우는 frontend를 프로젝트 명으로 정해줬음.
Django 세팅
https://docs.djangoproject.com/ko/4.2/intro/tutorial01/
Django
The web framework for perfectionists with deadlines.
docs.djangoproject.com
이걸 참고해서 프로젝트를 생성하고, 내 경우는 backend를 프로젝트 명으로 정해줬다.

장고 앱서버 실행시 이와 같은 화면이 나오면 정상적으로 세팅이 된것이다.
django + nuxt3 통합
사실상 통합이라고 할만한것도 없다.
django가 사용하는 포트로 nuxt3에서 axios나 fetch를 통해서 request를 보내줄 수 있는 코드만 작성하면 된다.
Backend 단 테스트 코드 작성
생성한 backend 프로젝트 폴더 내에
backend/backend/views.py 파일을 아래 코드를 포함하여 생성
from django.http import JsonResponse def test(request): return JsonResponse({"msg": "test"})
backend/backend/urls.py 파일을 아래와 같이 수정
from django.contrib import admin from django.urls import path from .views import index urlpatterns = [ path("api/test/", index, name="index"), path("admin/", admin.site.urls), ]
127.0.0.1:8000/api/test/ 주소를 호출하였을때 JSON형태의 응답이 정상적으로 오는지 확인해보면된다.

Frontend 단 호출코드 작성
frontend/nuxt.config.ts
frontend/nuxt.config.ts // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ runtimeConfig: { // Config within public will be also exposed to the client public: { apiBase: "http://127.0.0.1:8000/api", }, }, })
frontend/app.vue
<template> <h1> {{ test.msg }} </h1> </template> <script setup> const config = useRuntimeConfig(); const { data: test } = await useFetch(`${config.public.apiBase}/test/`); </script>

test라는 글자가 잘 출력되면 호출이 정상적으로 된것이다.
'IT > fullstack' 카테고리의 다른 글
CI/CD slack jenkins 연동 오류 jenkins slack Client error : Illegal character in query at index 81 (0) | 2024.02.02 |
---|---|
기존 서버에 새로운 도메인 추가 시 ssl 재적용 방법? (0) | 2024.01.03 |
Docker 환경에서 ec2 lightsail port 열었는데도 안될 때 (0) | 2023.12.13 |
django + vue + nuxt -> django + htmx으로 스택을 전환하려는 이유 (1) | 2023.11.20 |