express 相关问题

Express是一个最小且灵活的Node.js Web应用程序框架,为构建Web应用程序提供了一组强大的功能。 https://expressjs.com

React Native 应用程序在构建模式下访问 Stripe 支付屏幕时意外崩溃

我在 React Native 中开发了一个应用程序,可以使用 Stripe 执行金融交易。下面的函数负责访问我开发的 Node.js 服务器的端点。没有

回答 1 投票 0

查询 MongoCollection 以获取两个日期字符串之间的数据

我尝试创建一个查询来搜索两个日期字符串之间的所有集合,但是我所有的尝试都失败了,每次我尝试查询时它总是不返回任何结果 这个...

回答 1 投票 0

程序重定向到另一个页面,但其 html 未显示。程序显示“无法获取/页面”

这里是 Express + Nodejs 的新手。我的程序正在尝试将用户从主页重定向到注册页面。我将 a href 属性添加到我的一个按钮来执行此操作: 这里是 Express + Nodejs 的新手。我的程序正在尝试将用户从主页重定向到注册页面。我将 a href 属性添加到我的一个按钮来执行此操作: <div class="button1"> <div class="icon"> <i class="fa-solid fa-user-plus fa-xl" style="color: #ffffff; margin-right:10px;"></i> </div> <div class="button-content"> <h3 class="buttonl"><a href="acc_id.js">Get Account ID</a></h3> </div> </div> 我还将其添加到我的 index.js 文件中: app.get("/", (req, res) => { res.render("acc_id"); }); 但是,虽然选项卡正在重定向,但程序并未显示 acc_id.js 内的 html 页面。我收到响应“无法获取/acc_id.js”。 这也是 acc_id 文件: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Responsive Registration Form</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <link rel="stylesheet" href="/css/forms.css"/> </head> <body> <div class="container"> <h1 class="form-title">Registration</h1> <form action="#"> <div class="main-user-info"> <div class="user-input-box"> <label for="fullName">Full Name</label> <input type="text" id="fullName" name="fullName" placeholder="Enter Full Name"/> </div> <div class="user-input-box"> <label for="email">Email</label> <input type="email" id="email" name="email" placeholder="Enter Email"/> </div> <div class="role"> <label for="role">Are you a student or a teacher?</label> <select name="Position" id="position" required> <option value="student">Student</option> <option value="teacher">Teacher</option> </select> </div> <div class="Strand"> <label for="strand">Strand:</label> <select name="Strand" id="Strand" placeholder="Strand"required> <option value="abm">ABM</option> <option value="sc">ESTEM-C</option> <option value="se">ESTEM-E</option> <option value="sh">ESTEM-H</option> <option value="HUMSS">HUMSS</option> <option value="tvl">TVL</option> <option value="N/A">N/A (For teachers)</option> </select> </div> <div class="Class number"> <label for="classnum">Class Number</label> <input type="number" id="cnum" name="" placeholder="Enter Class Number"/> </div> <div class="user-input-box"> <label for="idNumber">ID Number</label> <input type="Number" id="idNum" name="phoneNumber" placeholder="Enter ID Number"/> </div> <div class="user-input-box"> <label for="password">Password</label> <input type="password" id="password" name="password" placeholder="Enter Password"/> </div> <div class="user-input-box"> <label for="confirmPassword">Confirm Password</label> <input type="password" id="confirmPassword" name="confirmPassword" placeholder="Confirm Password"/> </div> </div> </div> <div class="form-submit-btn"> <input type="submit" value="Register"> </div> </form> </div> </body> </html> 我一直在尝试重组文件/文件夹结构,例如在视图文件夹中添加/删除 acc_id.ejs,以及将其添加为根目录中的 .js 文件,但没有任何反应。如果有人能澄清我应该将包含用户填写表格的页面放在哪里,我也将不胜感激;根据我读到的内容,它们应该位于视图文件夹中,但同时我很困惑,因为我读到“布局”应该位于这个文件夹中,但我不确定这些布局到底是什么。 href 需要提供路由路径,并且该路由路径必须像通常那样提供路由处理程序。 index.html <h3 class="buttonl"><a href="/regform">Get Account ID</a></h3> regform 路由处理程序 服务器.js app.get('/regform', (req, res) => { let fileName = 'reg.html'; res.sendFile(fileName, options, function (err) { if (err) { next(err); } else { console.log('Sent:', fileName); } }); }); 另请注意,此路由路径提供的服务是普通的 html 文件。代码中引用的 reg.htm 相当于您的 acc_id.js 现在关于目录结构,它可以是普通的,也可以是嵌套的。要点是sendFile需要有静态路径,如下提供。在这种情况下,目录结构保持简单 - 没有嵌套。 服务器.js var options = { root: path.join(__dirname, './'), dotfiles: 'deny', headers: { 'x-timestamp': Date.now(), 'x-sent': true, }, }; 仅供参考,这是根路由处理程序。 服务器.js app.get('/', function (req, res, next) { let fileName = 'index.html'; res.sendFile(fileName, options, function (err) { if (err) { next(err); } else { console.log('Sent:', fileName); } }); });

回答 1 投票 0

Node Express 未发送自定义错误消息

我正在尝试制作一个 npm 模块,其中用户需要发送他的令牌和 id 才能连接。 这是模块代码: var https = require('https'); var fetch = require('node-fetch') ...

回答 4 投票 0

如何在 Express 应用程序中使用 MSAL 节点刷新访问令牌?

我目前正在开发一个 Express 应用程序,在该应用程序中,我按照 Microsoft 的教程,使用适用于 Node.js 的 Microsoft 身份验证库 (MSAL) 实现了身份验证。 我有

回答 1 投票 0

错误处理在express中输出html而不是json

我按照express.js的教程制作了一个简单的错误处理程序 函数 clientErrorHandler(err, req, res, next) { if (req.xhr) { console.log('clienterrorhandler', err); res.status(500).

回答 1 投票 0

Cors错误,我已经尝试过了,我被问了很多次,但我似乎没有找到解决方案

从源“http://127.0.0.1:5173”访问“http://localhost:5000/user/login”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:...

回答 1 投票 0

RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效状态代码:4

我在尝试运行我的网络应用程序时收到此错误,该应用程序应该是一个简单的计算器。我将 Nodejs 与express.js 框架结合使用。 这是我的主要 js 文件: 常量表达 =

回答 2 投票 0

docker后端镜像UTF-8编码问题

我尝试创建mysql和nodejs Express图像 当我运行 mysql 和后端容器并打开我的前端时 英文文本可以显示,但如果数据是泰文文本,当我使用 mysql2 获取泰文文本时 该...

回答 1 投票 0

使用express-validator确保整数或整数数组

我在尝试 Express 时对验证器感到困惑。 我收到的路由可选参数 flags 应该是整数或整数数组。 整数数组部分被检查...

回答 1 投票 0

node.js 和express Session 不起作用

会话无法正常工作。我在登录后请求中保存了会话令牌,但在仪表板请求中没有收到令牌 我究竟做错了什么? const express = require('express'); 常量 axios = r...

回答 1 投票 0

类型错误:无法读取反应中的属性长度

在这个应用程序中,我使用reactjs作为前端节点js来支持...... 当我尝试返回反应中数组的长度时,我遇到了问题。错误是“TypeError:无法读取属性”len...

回答 1 投票 0

使用 mongoose 在架构中定义嵌套对象

models.movies.js: const 猫鼬=需要(“猫鼬”) const likesModel=require("./models.like") const movieSchema=mongoose.Schema({ _ID:{ 类型:数字, 要求...

回答 1 投票 0

为什么浏览器会自动将http请求转为https

我使用节点index.js在亚马逊ec2实例上托管了一个express.js应用程序。在我的 index.html 中,我有以下 2 行 <p>我使用 <pre><code>node index.js</code></pre> 在亚马逊 ec2 实例上托管了一个express.js 应用程序。在我的 <pre><code>index.html</code></pre> 中,我有以下 2 行 <pre><code>&lt;head&gt;</code></pre></p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code> &lt;script type=&#34;module&#34; src=&#34;http://51.20.7.73:5000/buildjs.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;http://51.20.7.73:5000/buildcss.css&#34;&gt;</code></pre> </div> </div> <p></p> <p>但问题是,当这个 HTML 在 chrome 浏览器中呈现时,这些请求会自动转换为 https 而不是 http,这会在控制台中出现如下错误</p> <p><a href="https://i.sstatic.net/DdWGM8D4.png" rel="nofollow noreferrer"><img src="https://cdn.txt58.com/i/AWkuc3N0YXRpYy5uZXQvRGRXR004RDQucG5n" alt="error in console"/></a></p> <p>我的页面本身托管到http:<pre><code>http://51.20.7.73:5000/</code></pre> 当我在浏览器中单独打开 <pre><code>http://51.20.7.73:5000/buildjs.js</code></pre> 时,它可以正确提供文件。</p> <p>我不知道为什么这些请求会自动传输到 HTTPS,但由于这个原因我的反应页面无法工作,有人可以帮忙吗?谢谢!</p> </question> <answer tick="false" vote="0"> <p>这可能是这个问题的重复吗?</p> <p><a href="https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome">https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome</a></p> <p>或者更准确地说,您想在 Chrome 中禁用 https 转换还是调整您的代码以使其可以处理 http 和 https?</p> </answer> <answer tick="false" vote="0"> <p>您必须使用 <pre><code>helmet</code></pre> 来表达,以防止 <pre><code>hsts</code></pre> 相关标头指示浏览器对所有内容使用 <pre><code>HTTPS</code></pre>。</p> <pre><code>const express = require(&#39;express&#39;); const helmet = require(&#39;helmet&#39;); const app = express(); // Use Helmet to set various HTTP headers for security, except HSTS app.use(helmet({ hsts: false // Disable HSTS })); // Define your routes app.get(&#39;/&#39;, (req, res) =&gt; { res.send(&#39;Hello, world!&#39;); }); // Start the server const port = process.env.PORT || 3000; app.listen(port, () =&gt; { console.log(`Server running on port ${port}`); }); </code></pre> </answer> </body></html>

回答 0 投票 0

如何让session变量在页面之间传递?

首先,我有多个 Express 网页。我将变量保存到发布请求中的会话中,然后它重定向到不同的页面。在该页面上,我尝试访问该变量。但它

回答 1 投票 0

Firestore .data() 返回未定义

我正在制作一个使用react和nodejs作为服务器的应用程序。我正在使用 firebase auth 和 firestore。 我有一个问题,当我创建用户时一切都很好,用户创建得很好,用户 uid 和...

回答 1 投票 0

错误:在 Express.js 应用程序中找不到模块“../controllers/userController”

我正在开发一个全栈项目,使用 Express.js 作为后端,使用 MongoDB 作为数据库。我在尝试启动服务器时遇到错误。错误信息如下: 错误:

回答 1 投票 0

为什么使用 http 获取 POST 到远程数据库可以工作,但不能使用 https 协议?

我正在使用 VueJS、Nginx、Express 和 MongoDB 开发一个网站。如果我使用 http 协议从本地计算机发出指向远程数据库的 PUT 请求,我的后端运行良好,但是......

回答 1 投票 0

无法通过 https 向远程数据库进行获取 POST,但可以使用 http

我正在使用 VueJS、Nginx、Express 和 MongoDB 开发一个网站。如果我使用 http 协议从本地计算机发出指向远程数据库的 PUT 请求,我的后端运行良好,但是......

回答 1 投票 0

2从 Fastify 转换后,Hire Webhook URL 在 Express.js 中不起作用

我最近将处理 2Hire webhooks 的 Fastify 应用程序转换为 Express.js。但是,Webhook URL 并未按我的预期触发。 2Hire webhooks 订阅 API 文档:https://developer.2hi...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.