如何使用node和ejs停止对index.html文件的访问

qltillow  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(359)

如何停止对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')
vsaztqbk

vsaztqbk1#

使用来自的静态资产的应用程序 public 其中包括你的 index.html 文件
您可以从静态源中删除index.html

app.get("/", function(req, res){
    res.sendFile(path.join(__dirname, "views", "index.html"));
});

或者,您可以提供静态文件夹的基本路径。

app.use('/public' ,express.static(path.join(__dirname, 'public')));

相关问题