• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 part1 강의에서 css 적용이 안되는 부분 질문드립니다.

part1 강의에서 css 적용이 안되는 부분 질문드립니다.

  • 이 주제에는 2개 답변, 2명 참여가 있으며 햄찌2 년, 7 월 전에 전에 마지막으로 업데이트했습니다.
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #57928

    햄찌
    참가자
    <!-- index.html -->
    <!-- Bootstrap -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
        <link rel="stylesheet" href="/public/css/style.css">
    
    
    <!-- server.js -->
    
    const express = require('express')
    const app = express()
    const bodyParser= require('body-parser')
    var path = require('path')
    app.use(bodyParser.urlencoded({extended: true}));
    app.use(express.static(path.join(__dirname, 'public')));
    app.listen(8080, function() {
        console.log('listening on 8080')
    })
    app.get('/', function(요청, 응답) { 
        응답.sendFile(__dirname +'/index.html')
    })
    app.post('/add', function(요청, 응답){
        console.log(요청.body);
        응답.send('전송완료')
    });
    <!-- style.css -->
    
    .email-form-bg {
        background-color: rgb(218, 228, 255);
        padding: 1px;
    }
    .email-form {
        display: block;
        width: 80%;
        max-width: 600px;
        background-color: white;
        border-radius: 8px;
        margin: 50px;
        margin-left: auto;
        margin-right: auto;
        padding: 50px;
    }
    .navbar {
        margin-bottom: 0;
    }
    
    
    이렇게 작성했는데 http://localhost:8080/ 으로 들어가면 css 적용이 안되어 나옵니다.
    구글링해보니 node js는 css 같은 정적파일을 전달하려면 css를 public 폴더에 넣고 
    app.use(express.static(path.join(__dirname, 'public'))); 를 추가하라고 해서 그렇게 했더니
    http://localhost:8080/css/style.css 에 접속하면 해당 css가 잘 뜹니다.
    하지만 여전히 http://localhost:8080/ 에 접속했을때 css가 적용되어있지 않습니다.
    css 적용되어 나오게 하는 방법이 궁금합니다.
    감사합니다~!
    #57969

    codingapple
    키 마스터
    css파일 첨부시 /css/style.css 아니면 /style.css만 써봅시다 
    
    #58035

    햄찌
    참가자
    public은 생략하는거군요 감사합니다~!!
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠