我如何停止使用节点和 ejs 访问我的 index.html 文件
How do i stop access to my index.html file using node and ejs
我如何停止访问索引 .html 文件并让人们在 home.ejs 上注册,我正在构建一个静态网站,但现在制作一个网络应用程序并希望人们注册。
我注释掉了索引部分,但索引仍然排在第一位而不是首页。
我希望人们先注册,然后再使用该应用程序
这是我的代码。
//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
的静态资产,其中包括您的 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')));
我如何停止访问索引 .html 文件并让人们在 home.ejs 上注册,我正在构建一个静态网站,但现在制作一个网络应用程序并希望人们注册。
我注释掉了索引部分,但索引仍然排在第一位而不是首页。
我希望人们先注册,然后再使用该应用程序
这是我的代码。
//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
的静态资产,其中包括您的 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')));