简体   繁体   English

javascript .get 函数在开发中有效,但在生产中无效

[英]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.

相关问题 JavaScript在开发中发挥作用,而不在生产中发挥作用(Heroku) - JavaScript Works in Development, Not in Production (Heroku) JavaScript开发和生产模式 - JavaScript development and production mode Javascript“开发”和“生产 - Javascript “development” and "production 在开发和生产站点中使用Javascript获得不同的基本网址 - Get Different Base Url using Javascript in Development and Production Site Javascript requirejs正在开发中,但在生产中编译 - Javascript requirejs in development but compiled in production Rails 4 - 在生产中,我的 javascript 已加载,但在开发中运行良好时不起作用 - Rails 4 - In production my javascript is loaded but does not work while it works well in development javascript代码部分未在测试环境中执行,可在生产,开发中使用(Rails 3应用) - javascript code partially not executed in test environment, works in production, development (Rails 3 app) JavaScript函数拒绝在生产服务器上运行,但在本地服务器上运行 - JavaScript function refuses to work on production server but works on local server 条件在本机生产中反应失败,但在开发中有效 - Condition fails in react native production, but works in development 地理位置开发工作不在生产中 - Geo-location works in development not in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM