在localhost上工作的链接在部署服务器上不工作 [英] link working on localhost not working on deploy server

查看:43
本文介绍了在localhost上工作的链接在部署服务器上不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a web page rendered by a link running in localhost, but it fails on deply server.

...
    //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'))

推荐答案

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

You're likely misleading the path of the file that changed from your localhost to deploy server.

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

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

change it to the REAL actual path of your app, you can get it from PHP via: $_SERVER['DOCUMENT_ROOT'] (and add sub-folders from this path if necessary)

它应该可以工作!

这篇关于在localhost上工作的链接在部署服务器上不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆