Inflearn brand logo image

인프런 커뮤니티 질문&답변

안연수님의 프로필 이미지
안연수

작성한 질문수

한 번에 끝내는 자바스크립트: 바닐라 자바스크립트로 SPA 개발까지

CityList 개발

CityList.js에서 api.js 파일의 API_URL이 렌더링이 안되는 오류가 있습니다!

해결된 질문

작성

·

89

·

수정됨

0

세션 9. 여행지정보 최종프로젝트 작성 중...

  1. CityList 개발 13:25분에서 CityList.js를 작성한 후 localhost:3000을 새로고침해도 전혀 변화없이 빈 화면만 출력이 됩니다!
    api.js에서 API_URL로 전달받을 https://trip-wiki-api.vercel.app/ 에서 도시 정보 40개 정보가 없더라고요, 그래서 웹 화면에 아무것도 출력되지 않아서 문의드립니다!

화면 캡처 2025-06-13 085203.png.webp

 

화면 캡처 2025-06-12 094032.png.webp

 

화면 캡처 2025-06-12 093807.png.webp화면 캡처 2025-06-12 093912.png.webp화면 캡처 2025-06-12 093941.png.webp
  • server.js 파일도 /*splat 로 변경해서 "start server" 노드 명령어로 터미널에서 출력되도록 수정 완료했지만, 홈페이지 이미지가 출력되지 않고 있습니다!

const express = require("express");
const path = require("path");
const app = express();
const PORT = 3000;

app.use(express.static(path.join(__dirname, "..")));

app.get("/*splat", (req, res) => {
  res.sendFile(path.join(__dirname, "..", "index.html"));
});

app.listen(PORT, () => {
  console.log("START SEVER");
});
export default function CityList({ $app, initialState }) {
  this.state = initialState;
  this.$target = document.createElement("div");
  this.$target.className = "city-list";

  $app.appendChild(this.$target);

  this.template = () => {
    let temp = `<div class="city-items-container">`;
    if (this.state) {
      this.state.cities.forEach((elm) => {
        temp += `
            <div class="city-item" id=${elm.id}>
                <img src=${elm.image}></img>
                <div class="city-item-info">${elm.city}, ${elm.country}</div>
                <div class="city-item-score">⭐ ${elm.total}</div>
            </div>
            `;
      });
      temp += `</div>`;
    }
    return temp;
  };

  this.render = () => {
    this.$target.innerHTML = this.template();
  };

  this.setState = (newState) => {
    this.state = newState;
    this.render();
  };
  this.render();
}

답변 1

0

효빈 Hyobin님의 프로필 이미지
효빈 Hyobin
지식공유자

안녕하세요 안연수님!

https://trip-wiki-api.vercel.app/?start=0

강의에서 사용되는 api는 위와같이 start=startIdx 를 뒤에 작성해주어야합니다.

다만 수강생분들이 헷갈리지 않도록 https://trip-wiki-api 에도 접속 가능하게 변경해둔 상태이니, 다시 한 번 확인 부탁드릴게요! 감사합니다.

안연수님의 프로필 이미지
안연수

작성한 질문수

질문하기