doq13207 2019-04-09 01:53
浏览 434

如何集成WordPress和NodeJS?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖