为什么我的网站下载而不是打开?
因此,我刚刚启动了一个新项目,当我尝试打开Localhost时,该文件会继续下载。这个项目中几乎没有任何内容,这是我的整个服务器:
// initialize server
const express = require("express");
const app = express();
app.engine(".ejs", require("ejs").__express);
app.set("view engine", "ejs");
app.use(express.static(__dirname+"views"));
app.use(express.static(__dirname+"public"));
// start server
app.listen(3000, function(){
console.log("listening on port 3000")
});
// get html
app.get("/start", function(req, res){
res.sendFile(__dirname+"/views/homepage.ejs")
});
我也有一个homepage.ejs,只有文本“ hello”和“空文件夹”视图和public> css。当我设置它时,我可以在编写服务器代码并创建文件夹后打开主页(它显示了文本,所有内容),但是当我尝试创建样式表并为下载的主页的背景着色时。然后,我删除了CSS表并重新启动服务器,它一直在下载。我正在通过Github从事更大的项目,但我从来没有遇到过这个问题,而当我在自己的项目上时,它就会发生。我尝试复制我的一些较旧的小型项目,这些项目总是有效,但是一旦我更改了几件事(没关系),它再次下载。我的OneDrive中有文件夹,所以我在笔记本电脑上打开它们,同样的问题。我在其他浏览器(Chrome,Explorer,firefox)的其他问题中打开它们。有人知道如何修复它吗?
编辑:如果有帮助
So I just started a new project and the file keeps downloading when I try to open localhost. There is barely anything in this project this is my whole server:
// initialize server
const express = require("express");
const app = express();
app.engine(".ejs", require("ejs").__express);
app.set("view engine", "ejs");
app.use(express.static(__dirname+"views"));
app.use(express.static(__dirname+"public"));
// start server
app.listen(3000, function(){
console.log("listening on port 3000")
});
// get html
app.get("/start", function(req, res){
res.sendFile(__dirname+"/views/homepage.ejs")
});
I also have the homepage.ejs with only a text "hello" and empty folders views and public>css. When I set it up I could open the homepage after I wrote the server code and created the folders (it showed the text, everything worked) but when I tried to create a stylesheet and color the background of my homepage it downloaded. I then deleted the css sheet and restarted the server, it keeps downloading. I'm working on bigger projects via github and I never had that problem it just happens when I'm on my own projects. I tried copying some older small projects of mine which always worked but as soon as I change a few things (doesn't matter what) it downloads again. I have the folders in my OneDrive so I opened them on my laptop, same problem. I opened them in other browsers (Chrome, Explorer, Firefox) same problem. Does anyone know how to fix it pls?
Edit: javascript project in vs code if that helps
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论