如何集成WordPress和NodeJS?

我有安装nodejs的共享托管,所以我可以在apache托管上使用node并可以运行HTML文件 很容易使用node.js文件,但我无法处理PHP文件。 </ p>

搜索后我找到了一个链接 Can 用Node.js处理PHP文件

我尝试使用“php-express”库来运行PHP文件但不幸的是它下载了PHP文件而不是运行它:</ p>

  var express = require('express')
var app = express()
var path = require('path');
var phpExpress = require('php-express')({
binPath:' php'
});
var bodyParser = require(“body-parser”);

app.use(bodyParser.urlencoded({
extended:true
}));
app.use(bodyParser。 json());

app.use('/',express.static(__ dirname));
app.set('views',path.join(__ dirname,'/ views'));
app.engine ('php',phpExpress.engine);
app.set('view engine','php');

app.all(/.+ \ .php $ /,phpExpress.router);

appa .get('/',function(req,res){
res.sendFile(path.join(__ dirname,'/ views / index.php'),function(err){
if(err){
res.status(500).send(err)
}
})
})

app.post ('/ registration',(req,res)=&gt; {
res.send(JSON.stringify(req.body));
});

(函数(req,res,next){
res.status(404).send(“抱歉找不到”)
});

app.listen(3000) ;
</ code> </ pre>

我想在调用example.com时运行WordPress站点,当我调用example.com/registration时,我可以使用post方法,如图所示 在上面的代码中。</ p>
</ div>

展开原文

原文

I have shared hosting where I installed nodejs, so I am able to use node on apache hosting and can run HTML files easily with node.js files but I can't process PHP files.

After searching I found a link Can't Process PHP files with Node.js so I tried "php-express" library in order to run PHP files but unfortunately its downloading PHP file instead of running it:

var express = require('express')
var app = express()
var path = require('path');
var phpExpress = require('php-express')({
    binPath: 'php'
});
var bodyParser = require("body-parser");

app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(bodyParser.json());

app.use('/', express.static(__dirname));
app.set('views', path.join(__dirname, '/views'));
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');

app.all(/.+\.php$/, phpExpress.router);

app.get('/', function (req, res) {
  res.sendFile(path.join(__dirname , '/views/index.php'), function (err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})

app.post('/registration', (req, res) => {
  res.send(JSON.stringify(req.body));
});    

app.use(function (req, res, next) {
    res.status(404).send("Sorry can't find that")
});

app.listen(3000);

I want to get running WordPress site when I call example.com and when I call example.com/registration then I can able to use post method as shown in the code above.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问