[英]javascript .get function works in development but not production
Below is code where the client is trying to get data from the server.下面是客户端尝试从服务器获取数据的代码。 Locally running my server on node.js, this works great.
在 node.js 上本地运行我的服务器,这很好用。 However, when I push to my server, I get
/getSettings 500 (Internal Server Error)
.但是,当我推送到我的服务器时,我收到
/getSettings 500 (Internal Server Error)
。 My index gets hit when the other request is made '/'
so I know the endpoint can be hit.当另一个请求发出
'/'
时,我的索引被命中,所以我知道可以命中端点。 But why not this other get?但为什么不是这个其他得到?
Node.js is running on my server as a runtime. Node.js 作为运行时在我的服务器上运行。
SERVER code (app.js):服务器代码(app.js):
const express = require('express');
var path = require('path');
var Config = require('./config.js'), conf = new Config();
const app= express();
const port = 3000;
app.listen(port, function(error){
if(error) {
console.log('Server failed to listen: ', error)
} else{
console.log('Server is listening on port: ' + port)
}
});
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get("/getSettings", function(require, response){
response.json({ configuration: conf });
});
app.use(express.static(path.join(__dirname, 'public')));
CLIENT Code:客户代码:
<script>
window.onload = function()
{
$.get("/getSettings", function( data )
{
//do stuffs
});
};
</script>
I found a fix.我找到了解决办法。
/getSettings
needs an empty folder called getSettings. /getSettings
需要一个名为 getSettings 的空文件夹。 So if anyone else has a scenario where root works fine, but no other routes do, this may likely be your issue.因此,如果其他人遇到 root 可以正常工作但没有其他路由可以正常工作的情况,这可能是您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.