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 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器