在本地主机上工作的链接在部署服务器上不工作

时间:2019-07-31 02:21:39

标签: javascript node.js firebase google-cloud-functions

我有一个通过本地主机中运行的链接呈现的网页,但在Deply服务器上失败。

...
    //this is html page
    var view = document.createElement('a');
    $(view).addClass('btn btn-primary btn-sm')
    view.textContent = "Update";
    view.setAttribute('href', window.location.href+'/'+doc.id)
    //note : window.location.href = http://localhost:5000/<project>/app/home/
    ...`

    //this is server side
        app.get('/home/:id', (req, res) => {
            res.render('viewData', {
                params : req.params.id
            })
        })
    exports.app = functions.https.onRequest(app);

其渲染:

app.get('*', (req,res) => res.send('Page not found'))

1 个答案:

答案 0 :(得分:0)

您可能误导了从localhost更改为部署服务器的文件的路径。

您说:window.location.href = http://localhost:5000/<project>/app/home/

将其更改为应用程序的REAL实际路径,您可以通过以下方式从PHP获取它:  $_SERVER['DOCUMENT_ROOT'](并在必要时从此路径添加子文件夹)

它应该可以工作!

相关问题