웹 콘솔창에 자꾸 GET http://localhost:3000/js/home/login.js net::ERR_ABORTED 404 (Not Found)
이런 오류가 뜨네요... 도저히 해결방법이 안 나옵니다...
위에 주소로 들어가면 Cannot GET /js/home/login.js 로 뜹니다.
app.js 코드입니다.
const express = require("express");
const path = require('path');
const bodyParser = require("body-parser")
const app = express();
const home = require("./src/routes/home");
app.set("views", "./src/views");
app.set("view engine", "ejs");
app.use('/public', express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use("/", home);
module.exports = app;
login.ejs코드입니다.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset ="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src = "/js/home/login.js" defer></script>
<title>Document</title>
</head>
<body>
<input id="id" type = "text" placeholder="아이디"><br>
<input psword="psword" type="text" placeholder="비밀번호"><br>
<button>로그인</button>
</body>
</html><samp></samp>
login.js 코드입니다
"use strict";
const id = document.querySelector("#id"),
psword = document.querySelector("#psword"),
loginBtn = document.querySelector("button");
loginBtn.addEventListener("click", login);
function login() {
const req = {
id: id.value,
psword: psword.value,
}
fetch("/login", {
method: "POST",
headers:{
"Content-Type" : "application/json",
},
body: JSON.stringify(req),
})
}