Skip to content

php-express downloads the page instead of rendering it  #15

Description

@avvie

basically i copy pasted you example and changed the directories, but when i request the page i get a download
php is the path

const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const submission = require('./models/submission');
const cors = require('cors');

const app = express();

var phpExpress = require('php-express')({

    // assumes php is in your PATH
    binPath: 'php'
});

app.set('views', path.join(__dirname, 'end-user/dist'));
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');

// routing all .php file to php-express
app.all(/.+\.php$/, phpExpress.router);
// Parsers for POST data
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: false, limit: '10mb' }));

// Point static path to dist
app.use(express.static(path.join(__dirname, 'end-user/dist')));

app.get('*', (req, res) => {
    console.log('HAllo?!');
    res.sendFile(path.join(__dirname, '/end-user/dist/index.php'));
});

console.log(__dirname);
/**
 * Get port from environment and store in Express.
 */
const port = process.env.PORT || '16484';
app.set('port', port);

/**
 * Create HTTP server.
 */
const server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */
server.listen(port, () => console.log(`API running on localhost:${port}`));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions