【发布时间】:2022-01-15 06:29:30
【问题描述】:
当我通过 VS 代码运行我的网页时,我的所有图片都会显示,但由于某种原因,当我通过 localhost 执行此操作时,没有任何图片或 CSS 被发送。这是我下面的代码,任何帮助将不胜感激。我试图在网上找到解决方案,但到目前为止似乎没有任何效果。
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="/public/CSS/index.css" type="text/css" />
<style>
body {
align-items: center;
text-align: center;
background-image: url("../Images/backgroundImages.png");
min-height: 100%;
}
h1 {
font-size: 30px;
line-height: 1;
justify-content: center;
color: #66fcf1;
align-items: center;
text-decoration: none;
}
h2 {
font-size: 100px;
text-decoration: none;
line-height: 1;
justify-content: center;
color: #66fcf1;
align-items: center;
}
p {
font-family: "Times New Roman", Times, serif;
font-size: 30px;
margin-left: 25%;
margin-right: 25%;
color: #c5c6c7;
}
a:hover {
color: white;
text-decoration: underline;
background-color: rgb(52, 52, 126);
}
a {
color: #1f2833;
background-color: #45a29e;
text-decoration: none;
}
.dropbtn {
background-color: #66fcf1;
color: #1f2833;
padding: 10px 20px;
border: none;
cursor: pointer;
position: fixed;
left: 50px;
top: 155px;
}
.dropdown {
position: fixed;
left: 0;
right: 0;
top: 175px;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
font-family: "Century Gothic", sans-serif;
}
.dropdown-content a {
padding: 12px 16px;
margin: 0;
text-decoration: none;
display: block;
font-size: 20px;
}
.dropdown-content a:hover {
background-color: #1f2833;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: black;
color: black;
}
</style>
<body>
<h1>CSCI 355 Dashboard</h1>
<div class="dropdown">
<button class="dropbtn">Menu</button>
<div class="dropdown-content">
<a href="https://github.com/aviglazer1998/355-Website">Github</a>
<a href="/public/HTML/weatherApp.html">Weather App</a>
<a href="/public/HTML/resume.html">Resume</a>
<a href="https://boilerplate-npm-4.aviglazer1998.repl.co">Managing Packages with NPM</a>
<a href="https://boilerplate-express-6.aviglazer1998.repl.co">Basic Node and Express</a>
<a href="https://boilerplate-mongomongoose-8.aviglazer1998.repl.co">MongoDB & Mongoose</a>
<a href="https://chalkboard-355.herokuapp.com/">Chalkboard</a>
<a href="https://github.com/aviglazer1998/chalkboard">Chalkboard Github</a>
<a href="/public/HTML/backpack.html">Backpack LL</a>
<a href="https://boilerplate-project-timestamp-1.aviglazer1998.repl.co">Timestamp Microservice</a>
<a href="https://boilerplate-project-headerparser.aviglazer1998.repl.co">Request Header Microservice</a>
<a href="https://boilerplate-project-urlshortener-1.aviglazer1998.repl.co">URL Shortner Microservice</a>
<a href="https://boilerplate-project-exercisetracker.aviglazer1998.repl.co">Excercise Microservice</a>
<a href="https://boilerplate-project-filemetadata.aviglazer1998.repl.co">Metadata Microservice</a>
</div>
</div>
</body>
</html>
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const router = express.Router();
const mongoose = require("mongoose");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const dbURI = "mongodb+srv://username:password@chalkboard.mc7fa.mongodb.net/chalkboard?retryWrites=true&w=majority";
mongoose
.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then((result) => app.listen(process.env.PORT || 8000))
.catch((err) => console.log(err));
app.use(express.static("/public"));
app.listen(() => {
console.log(`App listening on port 8000`);
});
app.get("/", (request, response) => {
response.sendFile(__dirname + "/public/HTML/index.html");
});
app.get("/public/HTML/index.html", (request, response) => {
response.sendFile(__dirname + "/public/HTML/index.html");
});
app.get("/public/HTML/resume.html", (request, response) => {
response.sendFile(__dirname + "/public/HTML/resume.html");
});
app.get("/public/HTML/weatherApp.html", (request, response) => {
response.sendFile(__dirname + "/public/HTML/weatherApp.html");
});
app.get("/public/HTML/backpack.html", (request, response) => {
response.sendFile(__dirname + "/public/HTML/backpack.html");
});
【问题讨论】:
-
用您的用户名和密码向我们显示 mongdob URI 并不聪明
-
谢谢,我编辑了
标签: javascript html css node.js express