This is a MontageJS demo that loads featured posts from a remote Wordpress blog and displays them in a touch-friendly user interface.
To run locally, follow these steps:
- Clone the popcorn GitHub repo in your desktop.
git clone git@github.com:montagejs/montage-wordpress.git
- Install Node modules dependencies
npm install
- Use NodeJS http-server or Spin up your preferred HTTP server and point your browser to the associated port to serve the popcorn directory.
npm run start
Note: During development MontageJS applications rely on XHR to load their various components and modules, which is why you will need a web server to serve the demo.
You can start NodeJS http-server using command:
npm run serve
Then open your favorite browser at (http://localhost:8080).
If you happen to have minit, the Montage Initializer, installed (
npm install minit -g
) you can runminit serve
from within the demo directory to set up a server on demand.
- Build a new version in
dist/
npm run build
- Serve
dist/
using NodeJS http-server
npm run serve:dist
The contents of the application are structured into the following directories and files:
- assets/ — Contains global styles and images for the application.
- node_modules/ — Contains the dependencies that power the application in development.
- ui/ — Contains the user interface components of the demo application.
- index.html — Is the entry-point HTML document for the application.
- LICENSE.md — Contains copyright information.
- package.json — Describes your app and its dependencies.
- README.md — Provides information about the demo application and how to install it.
To use your wordpress instance you will need to install WP REST API Plugin, see detailed instructions:
Then change default hostname
in ./ui/main.reel/main.js#L24 from demo.wp-api.org
to your wordpress domain.
To test custom domain you can also pass hostname query parameter, example:
We need WP REST API and WP OAuth Server on your WordPress site. Directly open WordPress plugin page and search and install these 2 plugins.
If your client is running on differnt domian. You need modify above 2 plugins a little bit to make them support cross domain ajax calls.
In WordPress plugin page clicks edit for WP REST API plugin. Modify plugin.php file. Search json_send_cors_headers
function and modify as following:
if ( $origin ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Headers: Content-Type, X-Requested-With, Authorization' );
}
Also in WordPress plugin page, let's edit WordPress OAuth Server plugin. In wp-oauth.php file. Change first couple lines as following
if (!function_exists('add_filter')) {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden');
exit();
}else{
header( 'Access-Control-Allow-Origin: http://wordpress.montage.com' );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Headers: Content-Type, X-Requested-With, Authorization' );
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
exit();
}
}
Note because we need send Basic Authorization data when doing token verifying. So Access-Control-Allow-Origin
must be set to a certain domain.
This demo application was created by the MontageJS team.