简体   繁体   English

如何在Heroku上到达前端? 后端启动并运行

[英]How to do I get at my frontend on Heroku? The backend is up & running

I finally got my node/express & mongodb running on Heroku...but how do I get at my frontend? 我终于在Heroku上运行了我的node / express和mongodb ...但是如何获得我的前端呢?

I am most familiar with a localHost setup, where I simply open my index.html, running localHost servers with MAMP.. 我对localHost设置最熟悉,在这里我只需打开index.html,并使用MAMP运行localHost服务器。

When I load myapp.herokuapp.com, I see a JSON of my MongoDB docs (currently empty) 加载myapp.herokuapp.com时,我看到了MongoDB文档的JSON(当前为空)

{
  "docs": []
}

And when I go to myapp.heroku.com/index.html I get my 404 error.. 当我访问myapp.heroku.com/index.html时,出现了404错误。

Where.. 404

This all makes sense, according to my express code: 根据我的明确代码,这一切都说得通:

app.get('/', function (req, res) {

    getAll(res);

});

app.get('*', function (req, res) {

    res.send("Where.. 404", 404);

});

How do I get to my index.html frontend? 我如何到达index.html前端? Is there any more code that would be helpful to see.. 还有更多的代码将对您有所帮助。

what app.use() calls do you have? 您有什么app.use()调用?

In particular, if you want to serve static .html files you need to add something along these lines (assuming your static file are located in the ./public sub-dir): 特别是,如果要提供静态.html文件,则需要沿以下./public行添加一些内容(假设您的静态文件位于./public子目录中):

app.use(express.static(__dirname + '/public'));

Further details: http://expressjs.com/api.html#app.use 更多详细信息: http : //expressjs.com/api.html#app.use

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NodeJs:如何从我的 HTML 前端访问我的 JavaScript 后端的功能? - NodeJs: How do I access the functions of my JavaScript backend from my HTML frontend? 如何将带有 Node 后端的 Svelte 前端部署到 Heroku? - How to deploy Svelte frontend with Node backend to Heroku? 如何正确划分前端和后端之间的任务? - How do I divide tasks between frontend and backend properly? 如何将文本字段输入从前端发送到后端 - how do I send a text field input from the frontend to the backend 如何从后端获取数据到前端? - How do i fetch data from the backend to the frontend? 如何在node.js-Backend和前端中的单独js文件中使用函数? - How can I use a function in a separate js file in my node.js-Backend as well as in my frontend? 如何将后端查询的结果返回到前端以显示在页面上 - How can I return the results of my backend Query onto my frontend to display on a page 我如何免费托管我的后端,以便我可以设置 cookie,因为 heroku 不能在 *heroku.com 域上? - How else do I host my backend free so i could set cookies since heroku can't on *heroku.com domains? 将Django后端与前端配对 - Pairing up Django backend with frontend 如何从 PHP 后端接收 JSON object 并将前端转换为 Z686155AF75A60A0F6E9D80E1 数组 - How do I receive a JSON object from PHP backend and convert to JavaScript array for frontend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM