<!-- 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 적용되어 나오게 하는 방법이 궁금합니다.
감사합니다~!