浏览器中显示的Node.js脚本而不是HTML文件

时间:2019-02-17 16:47:27

标签: node.js .htaccess express

感谢您看这个问题。

我的问题是:我有一个常规的nodejs,socket.io,可在localhost运行的快速脚本。 但是,当我尝试通过SSH连接到A2hosting在域中的Web服务器上运行时,index.js文件在浏览器中显示为纯文本,而不是告诉浏览器显示的html文件。

这是我的index.js文件中的express.js部分:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

var os = require('os');
http.listen(45123);
var html_dir = './html+css/';
app.get('/', function(req, res) {
    res.sendfile(html_dir + 'index.html');
});

app.get('/phone', function(req, res) {
    res.sendfile(html_dir + 'phone.html');
});
app.get('/back.png', function(req, res) {
    res.sendfile(html_dir + 'back.png');
});

这是我的.htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ views/index.js [NC,L]

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:45123/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:45123/$1 [P,L]
DirectoryIndex /views/index.js

这是我的浏览器中的样子: Screenshot of index.js in browser

这就是我的路径: 在文件夹public_html中,我具有文件夹视图(例如example.com/views)以及用于视图的.htaccess文件。在该文件夹视图中是index.js文件。

“启动”我的应用程序后,问题仍然出现。

我真正希望为解决该问题提供足够的信息。 尝试解决这个问题的成功 谢谢

0 个答案:

没有答案