Skip to content

Commit

Permalink
fixed static file issue
Browse files Browse the repository at this point in the history
Express server was unable to serve style.css file
  • Loading branch information
noobyco committed Apr 4, 2022
1 parent d067dac commit b79ef6d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const bodyParser = require("body-parser");
const app = express();

app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("static"));
app.use(express.static( __dirname + "/public"));

app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");

});

let name;
Expand Down Expand Up @@ -46,13 +47,13 @@ app.post("/main", function(req, res){
app.get("/main", function(req, res){
if(passwd == "raspian1155"){

res.sendFile(__dirname + "/main.html");
res.sendFile(__dirname + "/public/main.html");
}else{
res.write("Wrong password, YOU " + name);
res.send();
}
});

//Server listning...
app.listen(process.env.PORT || 8000);
app.listen(process.env.PORT || 8001);

File renamed without changes.
File renamed without changes
File renamed without changes
14 changes: 8 additions & 6 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<!-- Local CSS -->
<link rel="stylesheet" href="static/styles.css">
<link rel="stylesheet" href="./css/styles.css">
<title>LED CONTROLLER</title>
</head>
<body>
<div class="cont d-flex justify-content-center align-items-center p-2 bg-light">
<div class="head text-center m-2"><h2>LED CONTROLLER</h2></div>
<main class="card rounded p-2 text-center">
<div><img src="static/59837486.png"/></div>
<div><img src="./img/59837486.png"/></div>
<form action="/" method="POST">
<p>
<input type="text" name="name" class="form-control" placeholder="Name" required autofocus>
Expand All @@ -32,10 +32,12 @@
</form>
</main>
</div>

<div class="foot text-center"><h5>Made by Md Moinuddin</h5></div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>

</body>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</html>
2 changes: 1 addition & 1 deletion main.html → public/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<!-- Local CSS -->
<link rel="stylesheet" href="static/styles.css">
<link rel="stylesheet" href="./css/styles.css">
<title>LED CONTROLLER</title>
</head>
<body>
Expand Down

0 comments on commit b79ef6d

Please sign in to comment.