【发布时间】:2021-07-25 13:20:09
【问题描述】:
如何停止对 index .html 文件的访问并让人们在 home.ejs 上注册,我正在构建一个静态网站,但现在正在制作一个 Web 应用程序并希望人们注册。
我注释掉了索引部分,但索引仍然首先出现而不是首页。
我希望人们先注册,然后再使用该应用
这是我的代码。
//jshint esversion: 6
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended:true}));
/* app.get("/", function(req, res){
res.sendFile(path.join(__dirname, "public", "index.html"));
}); */
app.get("/home", function(req, res){
res.render("home")
})
app.listen(3000);
console.log('now the server is running')
【问题讨论】:
-
您使用来自
public的static assets,其中包括您的index.html文件。您可能不希望index.html作为静态资源