0

I was working with react-webpackage and running the project into node.js Now due to demand , i have to add some php files in the project but i don't know how to add php file in my project and now transfer my project from node.js to Xampp and run my project with xampp... can you please guide me with that.

I am using this webpack "https://github.com/srn/react-webpack-boilerplate".

And my webpack index.js file looks like this.

   'use strict';

   var fs = require('fs');
   var path = require('path');

   var express = require('express');
   var app = express();

  var compress = require('compression');
  var layouts = require('express-ejs-layouts');

  app.set('layout');
  app.set('view engine', 'ejs');
  app.set('view options', {layout: 'layout'});
  app.set('views', path.join(process.cwd(), '/server/views'));

  app.use(compress());
  app.use(layouts);
  app.use('/client', express.static(path.join(process.cwd(), '/client')));

   app.disable('x-powered-by');

   var env = {
    production: process.env.NODE_ENV === 'production'
   };

  if (env.production) {
 Object.assign(env, {
   assets: JSON.parse(fs.readFileSync(path.join(process.cwd(), 'assets.json')))
  });
 }



  app.get('/*', function(req, res) {
  res.render('layout', {
   env: env
 });
});

 var port = Number(process.env.PORT || 3001);
 app.listen(port, function () {
 console.log('server running at localhost:3001, go refresh and see magic');
 });

if (env.production === false) {
  var webpack = require('webpack');
  var WebpackDevServer = require('webpack-dev-server');

  var webpackDevConfig = require('./webpack.config.development');

   new WebpackDevServer(webpack(webpackDevConfig), {
    publicPath: '/client/',
  contentBase: './client/',
   inline: true,
  hot: true,
   stats: false,
   historyApiFallback: true,
   headers: {
  'Access-Control-Allow-Origin': 'http://localhost:3001',
  'Access-Control-Allow-Headers': 'X-Requested-With'
   }
  }).listen(3000, 'localhost', function (err) {
  if (err) {
     console.log(err);
   }

   console.log('webpack dev server listening on localhost:3000');
   });
  }

basically i want to declare some variables in php and fetch them to javascript.so just want to add one file in webpack(file named as index.php) and then all my project work normally

Thanks.

1 Answer 1

1

You can't run express on the same port of xampp, you have to use different ports (or different servers) to serve the php file.

Sign up to request clarification or add additional context in comments.

3 Comments

if i am ready to use to 2 servers like node and xampp... then how i can serve php file. can you please guide me more..
like how i should proceed with that in code.. i dont have any idea.. so please guide me
Your node run on port 3001, setup apache to run on 80 or anything else, put the php file at the htdocs folder. That's it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.