简体   繁体   English

如何在服务器中提供用于反应的 html 文件

[英]how to serve html file used in react in server

this is folder of code这是代码文件夹

在此处输入图片说明

I use node js and react to build a project I build design using react and controller to get data how I can serve html file in server so when run node server.js it open html page that I created I try this in server.我使用 node js 和 react 来构建一个项目我使用 react 和 controller 构建设计来获取数据如何在服务器中提供 html 文件,所以当运行 node server.js 时它打开我创建的 html 页面我在服务器中尝试这个。 js js

app.get('/english', function(req, res) {
    res.send(path.join(__dirname + '/index.html'));
});

and when i run this route localhost:3000/english i got this当我运行这条路线localhost:3000/english我得到了这个

/home/projects/folder/folder2/myproject/index.html

Read the html file first.首先阅读html文件。 You could assign it to a variable first then before sending.您可以先将其分配给变量,然后再发送。

暂无
暂无

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

相关问题 在Node.js服务器中提供HTML文件 - Serve html file in nodejs server 可以使用单个node.js服务器文件来服务HTML页面和处理来自该页面的POST请求吗? - Can a single node.js server file be used to both serve a HTML page and process POST requests from said page? 如何使用服务 static 文件与快递和反应? - how to use serve static file with express and react? 如何传递数据并从服务器向客户端提供html文件? - How can I pass data AND serve an html file from the server to the client? 如何在express.js中提供从服务器引用js文件并在客户端运行它的html? - How to serve html in express.js that references js file from server and run it on client side? Node Express Server:如何正确提供HTML文件(包括脚本和CSS)? (csp,相对路径和类似的东西) - Node Express Server : How to serve HTML file properly (scripts and css included) ? (csp, relative path and thing like that) 如何从高于我的服务器文件夹级别的目录在 Express 中提供 HTML 文件? - How do I serve an HTML file in Express from a directory which is a level above my server folder? 如何在用作nodejs服务器响应的html文件中包含外部脚本 - how to include external script in html file that is used as response in nodejs server 如何从服务器正确提供 create-react-app 索引? - How to properly serve the create-react-app index from the server? 使用Webpack后如何在静态服务器上提供我的React Webapp? - How to serve my React webapp on static server after using Webpack?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM