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

home2 게시판 Node.js, Express 게시판 서버에서 경로에 따른 라우팅문제가있습니다.

서버에서 경로에 따른 라우팅문제가있습니다.

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #63650

    정중식
    참가자
    app.get('/', function (req, res) {
      res.render('index.ejs');
    });
    app.get('/write', function (req, res) {
      res.render('write.ejs');
    });
    app.post('/add', function (req, res) {
      db.collection('counter').findOne(
        { name: '게시물갯수' },
        function (err, result) {
          var totalPost = result.totalPost;
          db.collection('post').insertOne(
            { _id: totalPost + 1, title: req.body.title, date: req.body.date },
            function (err, res) {
              console.log('저장완료');
              db.collection('counter').updateOne(
                { name: '게시물갯수' },
                { $inc: { totalPost: 1 } },
                function (err, result) {
                  if (err) {
                    return console.log(err);
                  }
                }
              );
            }
          );
          return res.redirect('/list');
        }
      );
    });
    app.get('/list', function (req, res) {
      db.collection('post')
        .find()
        .toArray(function (err, result) {
          res.render('list.ejs', { posts: result });
        });
      app.delete('/delete', function (req, res) {
        const id = parseInt(req.body._id);
        db.collection('post').deleteOne({ _id: id }, function (err, result) {
          res.status(200).send('성공');
        });
      });
      app.get('/edit', function (req, res) {
        res.render('edit.ejs');
      });
      app.get('/detail/:id', function (req, res) {
        // console.log(req.params.id);
        db.collection('post').findOne(
          { _id: parseInt(req.params.id) },
          function (err, data) {
            if (!data) {
              return res.status(404).send('not found');
            } else {
              res.render('detail.ejs', { data });
            }
          }
        );
      });
    
    위는 전체 코드입니다.
    
    문제는 
    
    app.get('/edit', function (req, res) {
        res.render('edit.ejs');
      });
    
    이 코드를 
    
    
    이렇게 '/' 경로 아래에다 깔아두면 url에 /edit를 치면 잘들어가지는데
    위의 전체 코드처럼 
    '/' 코드 바로 아래에다 안깔고 중간에 코드를 작성해두면 경로에 안들어가집니다.
    
    Cannot GET /edit 라는 문구가 페이지에 출력되구요
    에러메시지로는 
    GET http://localhost:8080/edit 404 (Not Found)
    9Refused to load the font '<URL>' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.
    
    이런 문구가 뜹니다 
    
    혹시 이럴땐 어떻게 해줘야할까요?
    
    
    
    #63676

    codingapple
    키 마스터
    컴퓨터 재시작해봅시다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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