From b84dd4107f8eded02a97c3f5b8e740d2b72d23b0 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Thu, 18 Jan 2018 06:49:06 +0530 Subject: [PATCH] Added very preliminary support for plugins --- .gitignore | 3 ++- config.js | 12 +++++------- php.js | 5 ++++- plugins/main.js | 10 ++++++++++ server.js | 15 ++++++++++----- 5 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 plugins/main.js diff --git a/.gitignore b/.gitignore index 1751843..2152cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules php -wp \ No newline at end of file +wp +plugins/*/ \ No newline at end of file diff --git a/config.js b/config.js index f40cc3f..b8c813a 100644 --- a/config.js +++ b/config.js @@ -1,13 +1,11 @@ +'use strict' + const { normalize } = require('path') module.exports = { port: 8080, - php: { - bin: normalize(__dirname + '/php/php-cgi.exe') - }, - wp: { - path: normalize(__dirname + '/wp'), - root: normalize(__dirname + '/wp/index.php') - } + phpBin: normalize(__dirname + '/php/php-cgi.exe'), + wpPath: normalize(__dirname + '/wp'), + plugins: [] } \ No newline at end of file diff --git a/php.js b/php.js index aa0d550..af0564d 100644 --- a/php.js +++ b/php.js @@ -1,6 +1,9 @@ // The base work for this module was found at // https://npmjs.com/package/node-php -// Credits to original author +// All credits to original author +// I've ES6'd and fixed deprecated Express functions + +'use strict' const url = require('url') const child = require('child_process') diff --git a/plugins/main.js b/plugins/main.js new file mode 100644 index 0000000..cc59663 --- /dev/null +++ b/plugins/main.js @@ -0,0 +1,10 @@ +'use strict' + +function plugins() { + const { plugins } = require('../config') + plugins.forEach(element => { + require('../plugins/' + element + '/main.js') + }) +} + +module.exports = plugins \ No newline at end of file diff --git a/server.js b/server.js index acb53fe..38db661 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,16 @@ -var express = require('express') -var php = require("./php") +'use strict' + +const express = require('express') +const php = require("./php") const config = require('./config') +const plugins = require('./plugins/main') -var app = express() +const app = express() app - .use("/", php.cgi(config.wp.path, config.php.bin)) + .use("/", php.cgi(config.wpPath, config.phpBin)) .listen(config.port) -console.log(`Server listening at ${config.port}!`) \ No newline at end of file +console.log(`⚡ Server listening at ${config.port}!`) + +plugins() // Run any plugins you need to while server runs