如何让nodejs提供静态内容而不必使用sendFile?与SENDFILE问题是,它会打开另一个选项卡,你从页面浏览页面,这里是一个片段...nodejs静态内容不使用sendFile
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/verify', function(request, response) {
var oneTimeCode = request.body.oneTimeCode;
var timeEntry = Date.now();
if (oneTimeCode == 'abc123') {
response.sendFile('/home/ubuntu/form.html');
} else {......
我可以使用像这样的地方SENDFILE的?
app.use(express.static(__dirname + '/home/ubuntu/form.html'));
取决于您希望如何访问它。从代码片段中删除'form.html',然后你就可以从'// domain.com/form.html',**以及该文件夹中的其他东西访问它。** sendFile不应该被打开尽管..一个新的标签,有效地使这是一个XY问题。 –
你是说这样看起来像这样吗? 'response.sendFile('//https://domain.com/form.html');' –
否.... //domain.com/form.html是客户端如何访问它。您将在节点中执行重定向以从验证路由中获取它。但请注意,这些都不会解决您主要关注的问题*“sendFile的问题在于您在每页导航时打开另一个选项卡”*,因为sendFile不这样做。因此,无论做什么,无论您在服务器端实施什么解决方案,都会继续这样做。 –