Giter Site home page Giter Site logo

postlight / headless-wp-starter Goto Github PK

View Code? Open in Web Editor NEW
4.4K 4.4K 650.0 11.6 MB

πŸ”ͺ WordPress + React Starter Kit: Spin up a WordPress-powered React app in one step

Home Page: https://postlight.com/labs/wordpress-react-starter-kit

License: GNU General Public License v2.0

PHP 17.41% CSS 0.24% JavaScript 63.58% Shell 5.05% Dockerfile 1.86% HTML 2.56% SCSS 9.31%
graphql-api headless-cms headless-wp labs nextjs react rest-api starter-kit wordpress wordpress-development

headless-wp-starter's Introduction

WordPress + React Starter Kit

Build status

Postlight's Headless WordPress + React Starter Kit is an automated toolset that will spin up three things:

  1. A WordPress backend that serves its data via the WP REST API and GraphQL.
  2. A sample React frontend powered by the WP GraphQL API, which supports posts, pages, categories, menus, search, and user sign-in.
  3. Another sample server-side rendered React frontend using Next.js powered by the WP REST API.

You can read all about it in this handy introduction.

What's inside:

  • An automated installer which bootstraps a core WordPress installation that provides an established, stable REST API.
  • A plugin which exposes a newer, in-progress GraphQL API for WordPress.
  • The WordPress plugins you need to set up custom post types and custom fields (Advanced Custom Fields and Custom Post Type UI).
  • Plugins which expose those custom fields and WordPress menus in the WP REST API (ACF to WP API and WP-REST-API V2 Menus).
  • JWT authentication plugins: JWT WP REST and JWT WP GraphQL.
  • All the starter WordPress theme code and settings headless requires, including pretty permalinks, CORS Allow-Origin headers, and useful logging functions for easy debugging.
  • A mechanism for easily importing data from an existing WordPress installation anywhere on the web using WP Migrate DB Pro and its accompanying plugins (license required).
  • A sample, starter frontend React app powered by GraphQL.
  • Another sample, starter frontend React app, server-side rendered via Next.js, powered by the WP REST API.
  • Docker containers and scripts to manage them, for easily running the frontend React apps and backend locally or deploying it to any hosting provider with Docker support.

Let's get started.

Install

Prerequisite: Before you begin, you need Docker installed. On Linux, you might need to install docker-compose separately.

Docker Compose builds and starts four containers by default: db-headless, wp-headless, frontend & frontend-graphql:

docker-compose up -d

Wait a few minutes for Docker to build the services for the first time. After the initial build, startup should only take a few seconds.

You can follow the Docker output to see build progress and logs:

docker-compose logs -f

Alternatively, you can use some useful Docker tools like Kitematic and/or VSCode Docker plugin to follow logs, start / stop / remove containers and images.

Optional: you can run the frontend locally while WordPress still runs on Docker:

docker-compose up -d wp-headless
cd frontend && yarn && yarn start

Once the containers are running, you can visit the React frontends and backend WordPress admin in your browser.

Frontend

This starter kit provides two frontend containers:

  • frontend container powered by the WP REST API is server-side rendered using Next.js, and exposed on port 3000: http://localhost:3000
  • frontend-graphql container powered by GraphQL, exposed on port 3001: http://localhost:3001

Here's what the frontend looks like:

Frontend Screencast

You can follow the yarn start output by running docker-compose logs command followed by the container name. For example:

docker-compose logs -f frontend

If you need to restart that process, restart the container:

docker-compose restart frontend

PS: Browsing the Next.js frontend in development mode is relatively slow due to the fact that pages are being built on demand. In a production environment, there would be a significant improvement in page load.

Backend

The wp-headless container exposes Apache on host port 8080:

This container includes some development tools:

docker exec wp-headless composer --help
docker exec wp-headless phpcbf --help
docker exec wp-headless phpcs --help
docker exec wp-headless phpunit --help
docker exec wp-headless wp --info

Apache/PHP logs are available via docker-compose logs -f wp-headless.

Database

The db-headless container exposes MySQL on host port 3307:

mysql -uwp_headless -pwp_headless -h127.0.0.1 -P3307 wp_headless

You can also run a mysql shell on the container:

docker exec db-headless mysql -hdb-headless -uwp_headless -pwp_headless wp_headless

Reinstall/Import

To reinstall WordPress from scratch, run:

docker exec wp-headless wp db reset --yes && docker exec wp-headless install_wordpress

To import data from a mysqldump with mysql, run:

docker exec db-headless mysql -hdb-headless -uwp_headless -pwp_headless wp_headless < example.sql
docker exec wp-headless wp search-replace https://example.com http://localhost:8080

Import Data from Another WordPress Installation

You can use a plugin called WP Migrate DB Pro to connect to another WordPress installation and import data from it. (A Pro license will be required.)

To do so, first set MIGRATEDB_LICENSE & MIGRATEDB_FROM in .env and recreate containers to enact the changes.

docker-compose up -d

Then run the import script:

docker exec wp-headless migratedb_import

If you need more advanced functionality check out the available WP-CLI commands:

docker exec wp-headless wp help migratedb

Extend the REST and GraphQL APIs

At this point you can start setting up custom fields in the WordPress admin, and if necessary, creating custom REST API endpoints in the Postlight Headless WordPress Starter theme.

The primary theme code is located in wordpress/wp-content/themes/postlight-headless-wp.

You can also modify and extend the GraphQL API, An example of creating a Custom Type and registering a Resolver is located in: wordpress/wp-content/themes/postlight-headless-wp/inc/graphql.

REST & GraphQL JWT Authentication

To give WordPress users the ability to sign in via the frontend app, use something like the WordPress Salt generator to generate a secret for JWT, then define it in wp-config.php

For the REST API:

define('JWT_AUTH_SECRET_KEY', 'your-secret-here');

For the GraphQL API:

define( 'GRAPHQL_JWT_AUTH_SECRET_KEY', 'your-secret-here');

Make sure to read the JWT REST and JWT GraphQL documentation for more info.

Linting

Remember to lint your code as you go.

To lint WordPress theme modifications, you can use PHP_CodeSniffer like this:

docker exec -w /var/www/html/wp-content/themes/postlight-headless-wp wp-headless phpcs -v .

You may also attempt to autofix PHPCS errors:

docker exec -w /var/www/html/wp-content/themes/postlight-headless-wp wp-headless phpcbf -v .

To lint and format the JavaScript apps, both Prettier and ESLint configuration files are included.

Hosting

Most WordPress hosts don't also host Node applications, so when it's time to go live, you will need to find a hosting service for the frontend.

That's why we've packaged the frontend app in a Docker container, which can be deployed to a hosting provider with Docker support like Amazon Web Services or Google Cloud Platform. For a fast, easier alternative, check out Now.

Troubleshooting Common Errors

Breaking Change Alert - Docker

If you had the project already setup and then updated to a commit newer than 99b4d7b, you will need to go through the installation process again because the project was migrated to Docker. You will need to also migrate MySQL data to the new MySQL db container.

Docker Caching

In some cases, you need to delete the wp-headless image (not only the container) and rebuild it.

CORS errors

If you have deployed your WordPress install and are having CORS issues be sure to update /wordpress/wp-content/themes/postlight-headless-wp/inc/frontend-origin.php with your frontend origin URL.

See anything else you'd like to add here? Please send a pull request!


πŸ”¬ A Labs project from your friends at Postlight. Happy coding!

headless-wp-starter's People

Contributors

ajshapell avatar alexiakl avatar alexmanno avatar ali-kalout avatar artemkozlenkov avatar dependabot[bot] avatar george-haddad avatar ginatrapani avatar glrodasz avatar hankroark avatar jakebresnehan avatar kevboh avatar lex111 avatar magidmroueh avatar markneub avatar mcorrello avatar modelm avatar mrclay avatar rachellesarkis1 avatar reemobeid17 avatar royelkhoury avatar skladany avatar tristanoneil avatar tylerbarnes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

headless-wp-starter's Issues

Routing works fine in dev but not in live mode

Thank you for your great work!

Its working fine when in dev mode ( yarn run dev )but I discovered once you deploy it (try with yarn run build and yarn run start), you can route to pages but 2 critical errors happen.

  1. the styling doesn't follow along on those pages.
  2. if you refresh on that url (or try to visit it), then you hit a 404 error.

Could you please help me figure this out? I tried with a fresh install and deploying to now and its the same in all scenarios.

localhost:8000/wp-admin leads to WP installation instead of the dashboard

First of all, thanks for your efforts, this is a great project.

so, when I echo $PATH:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

still, mysql commands seems to be pointing somewhere else.
FYI: I got MAMP installed but not running

when I run: yarn install && yarn start
I can access localhost:8000/wp-admin, but leads me to the WP installation instead of the dashboard.

when running that command, I see the error stated on the the Troubleshooting tier in the readme file:

Warning: mysql 5.7.21 is already installed and up-to-date
...
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I tried the solutions suggested there, but still have the same problem.
My ~/.bash_profile file doesn't add anything to the PATH variable, and I followed the steps listed here:
https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks

I'm stuck after that, don't know what else to try.

any ideas? thanks!

Do I have to deploy 2 projects?

If I were to deploy the Next.js app, do I need 2 separate hostings? One for Next.js and the other for WordPress. Is there a way to run both projects in one hosting?

Thanks

fix: menu page and post 404s

First of all, I gotta admit this is one of the coolest libraries I've seen around. I've been using nextjs for the past year but I got little to no clue on how WordPress works as an API backend. Hopefully, I can contribute a bit on the nextjs part when I get some free time.

So for the bugs, I've recorded a small gif that displays the 2 of them that I found initially by just installing the dependencies and running the project and adding a new page:

wordpressheadless

As you can see, when clicking on a page it will show a 404 not found for a second and then renders the page correctly.

The second one is when adding a new menu page it will direct you to the wrong URL and it will not find the correct path since the 404 error.

That's all, looking forward to being able to use this in the future! Thanks!

Install fails when trying to create robo path using Linux Subsystem for Windows

I'm using the Linux Subsystem for Windows and am unable to successfully install headless-wp-starter. I have followed repo instructions to the letter and installed latest version of yarn, nodejs, debconf-utils etc... , but still hangs when trying to create '/usr/bin/robo':

brent@PREC7710:/mnt/c/Users/brent/Desktop/headless-wp-starter$ yarn install
yarn install v1.6.0
$ chmod +x install.sh && ./install.sh
[sudo] password for brent:
Reading package lists... Done
Building dependency tree
Reading state information... Done
mysql-server is already the newest version (5.7.22-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
php is already the newest version (1:7.0+35ubuntu6.1).
php-mysql is already the newest version (1:7.0+35ubuntu6.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '/home/brent/.wget-hsts'. HSTS will be disabled.
--2018-05-02 13:14:36-- https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Resolving raw.githubusercontent.com... 151.101.184.133
Connecting to raw.githubusercontent.com|151.101.184.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4577919 (4.4M) [application/octet-stream]
Saving to: β€˜wp-cli.phar’

wp-cli.phar 100%[========================================================>] 4.37M 2.61MB/s in 1.7s

2018-05-02 13:14:38 (2.61 MB/s) - β€˜wp-cli.phar’ saved [4577919/4577919]

Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '/home/brent/.wget-hsts'. HSTS will be disabled.
--2018-05-02 13:14:38-- http://robo.li/robo.phar
Resolving robo.li... 104.27.148.169, 104.27.149.169, 2400:cb00:2048:1::681b:94a9, ...
Connecting to robo.li|104.27.148.169|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://robo.li/robo.phar [following]
--2018-05-02 13:14:39-- https://robo.li/robo.phar
Connecting to robo.li|104.27.148.169|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2437686 (2.3M) [application/octet-stream]
Saving to: β€˜robo.phar’

robo.phar 100%[========================================================>] 2.32M 2.75MB/s in 0.8s

2018-05-02 13:14:40 (2.75 MB/s) - β€˜robo.phar’ saved [2437686/2437686]

mv: cannot create regular file '/usr/bin/robo': Permission denied

  • Starting MySQL database server mysqld
    No directory, logging in with HOME=/
    [ OK ]
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    success Saved lockfile.
    $ robo wordpress:setup
    /bin/sh: 1: robo: not found
    error Command failed with exit code 127.
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

I noticed also that this created a robo.phar file and then on second attempt another robo.phar.1 file?

New feature: Jest tests for frontend

It would be super awesome to finally have display testing in a supported, common format using something like Jest. Perhaps it would be as simple as testing components for render changes with a faked API connection?

Featured Image

There is no Featured Image metabox on the post edit/new page. This is included by default in WordPress. I tried adding
'add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );',

but the functions.php file would not update.

Is this a React thing?

Thanks,
Doak

Analytics

I've added "react-ga": "^2.4.1" to my project.

I'm not sure on the best solution for integrating this. Should I try adding the page view code into components/PageWrapper?

Or should I include some code into each of the pages/*?

Frontend yarn run dev Error: Couldn't find preset "react-native" relative to directory

After cloning the repo I di the following steps:

yarn install && yarn start
cd frontend && yarn install && yarn run dev

When I go to localhost:3000 I get:

Error in /home/tithos/Web/react/nohead/frontend/pages/index.js?entry
Module build failed: Error: Couldn't find preset "react-native" relative to directory "/home/tithos/Web"
at /home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map ()
at OptionManager.resolvePresets (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/home/tithos/Web/react/nohead/frontend/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/home/tithos/Web/react/nohead/frontend/node_modules/next/node_modules/babel-loader/lib/index.js:50:20)

Ubuntu

Tim

CORS issue after installation on the frontend app

After installation, I'm getting this issue on the console of the frontend app:

Failed to load http://localhost:8080/wp-json/menus/v1/menus/main: Redirect from 'http://localhost:8080/wp-json/menus/v1/menus/main' to 'http://localhost:8080/wp-json/menus/v1/menus/main/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

screen shot 2017-11-10 at 11 16 46 pm

Also, if I use some Chrome plugin to allow CORS, I get the following error:

screen shot 2017-11-10 at 11 18 15 pm

I cannot install npm install && npm start

mv: cannot create regular file '/usr/bin/robo': Permission denied

[email protected] postinstall /home/nanda/Documents/07_react/headless-wp-starter-master
robo wordpress:setup

sh: 1: robo: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] postinstall: robo wordpress:setup
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR! /home/nanda/.npm/_logs/2018-05-08T03_19_39_205Z-debug.log

Can't get up & running on mac

When installing the wordpress portion of the repo with

yarn install && yarn start

I seem to get a lot of errors as below
[Exec] Running mysql -uroot -proot -h 0.0.0.0 -e 'create user if not exists wp_headless' sh: mysql: command not found [Exec] Exit code 127 Time 0.005s [Exec] Running mysql -uroot -proot -h 0.0.0.0 -e 'create database if not exists wp_headless' sh: mysql: command not found [Exec] Exit code 127 Time 0.003s [Exec] Running mysql -uroot -proot -h 0.0.0.0 -e "grant all privileges on wp_headless . * to wp_headless@localhost identified by 'wp_headless'" sh: mysql: command not found [Exec] Exit code 127 Time 0.003s [Exec] Running mysql -uroot -proot -h 0.0.0.0 -e 'flush privileges' sh: mysql: command not found [Exec] Exit code 127 Time 0.003s [Exec] Running wp core download --version=4.9 --locale=en_US --force in /Users/lukesmetham/Sites/arkitek-wp/wordpress Downloading WordPress 4.9 (en_US)... Using cached file '/Users/lukesmetham/.wp-cli/cache/core/wordpress-4.9-en_US.tar.gz'... Success: WordPress downloaded. [Exec] Done in 1.079s [Exec] Running wp core config --dbname=wp_headless --dbuser=wp_headless --dbpass=wp_headless --dbhost=0.0.0.0 in /Users/lukesmetham/Sites/arkitek-wp/wordpress env: mysql: No such file or directory [Exec] Exit code 127 Time 0.226s [Exec] Running wp db drop --yes in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or usewp config create. [Exec] Exit code 1 Time 0.247s [Exec] Running wp db create --yes in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.213s [Exec] Running wp core install --url=localhost:8080 --title="Postlight Headless WP Starter" --admin_user="nedstark" --admin_password="winteriscoming" --admin_email="[email protected]" --skip-email in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.205s [Exec] Running wp theme activate postlight-headless-wp in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.201s [Exec] Running wp theme delete twentyfourteen in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.266s [Exec] Running wp theme delete twentyfifteen in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.308s [Exec] Running wp theme delete twentysixteen in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.26s [Exec] Running wp theme delete twentyseventeen in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.227s [Exec] Running wp plugin delete akismet in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.227s [Exec] Running wp plugin delete hello in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.256s [Exec] Running wp plugin activate acf-to-wp-api advanced-custom-fields-pro akismet custom-post-type-ui wp-migrate-db-pro wp-migrate-db-pro-cli wp-migrate-db-pro-media-files wp-rest-api-v2-menus in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.277s [Exec] Running wp acf sync in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.294s [Exec] Running wp rewrite structure "/%year%/%monthnum%/%day%/%postname%/" in /Users/lukesmetham/Sites/arkitek-wp/wordpress Error: 'wp-config.php' not found. Either create one manually or use wp config create. [Exec] Exit code 1 Time 0.205s

Then once it completes if I go to localhost:8080 I get the standard WP install screen asking for language and database config, any help would be massivley appreciated, I've been dying for something like this for a long time!

Backend: Add wp-graphql plugin to expose GraphQL API

Graphql is a rest api replacement which lets you define which data you want to retrieve. Instead of this starter making a separate request for everything on the page, a single request could be made and then the data could be passed into all the places that are currently making individual requests. I think this should improve performance by a lot but I'm not a graphql expert. There is a wordpress plugin for graphql https://www.wpgraphql.com/

Incompatible library version: php requires version 20.0.0 or later, but libfreetype.6.dylib provides version 19.0.0

When I do yarn install I get:

$ robo wordpress:setup
dyld: Library not loaded: /usr/local/opt/freetype/lib/libfreetype.6.dylib
  Referenced from: /usr/local/bin/php
  Reason: Incompatible library version: php requires version 20.0.0 or later, but libfreetype.6.dylib provides version 19.0.0
/usr/local/bin/robo: line 2: 10041 Trace/BPT trap: 5       /usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/robo/1.1.1/libexec/robo.phar "$@"
error Command failed with exit code 133.

what might this be? How can I fix this?

yarn run deploy fetchError

Hey, this project is awesome!
I'm trying to run yarn run deploy but I keep getting this error when I load up localhost:3000

> next start
> Ready on http://localhost:3000
{ FetchError: request to http://localhost:8080/wp-json/postlight/v1/page?slug=welcome failed, reason: connect ECONNREFUSED 127.0.0.1:8080
    at ClientRequest.<anonymous> (/usr/src/app/node_modules/node-fetch/index.js:133:11)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:191:7)
    at Socket.socketErrorListener (_http_client.js:358:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at emitErrorNT (net.js:1279:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  name: 'FetchError',
  message: 'request to http://localhost:8080/wp-json/postlight/v1/page?slug=welcome failed, reason: connect ECONNREFUSED 127.0.0.1:8080',
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED' }

If I visit http://localhost:8080/wp-json/postlight/v1/page?slug=welcome in a browser I get the expected json appearing in the page.

feat: add custom WP endpoint for post slug

  • new endpoint should take a post slug, and return a post or an error depending if the post exists
  • account for slugs which have changed -- the original slug should return the post

Not able to install on MacOS robo: command not found

Running yarn install gives me.

yarn install v1.3.2
$ chmod +x install.sh && ./install.sh
Warning: wp-cli 1.5.0 is already installed and up-to-date
To reinstall 1.5.0, run `brew reinstall wp-cli`
./install.sh: line 23: wget: command not found
chmod: robo.phar: No such file or directory
Warning: mysql 5.7.21 is already installed and up-to-date
To reinstall 5.7.21, run `brew reinstall mysql`
Starting MySQL
 SUCCESS!
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[1/4] πŸ”  Resolving packages...
success Already up-to-date.
$ robo wordpress:setup
/bin/sh: robo: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Any ideas? Just cloned the latest.

Help getting this running on now.sh

Hi, in the original blog post https://trackchanges.postlight.com/introducing-postlights-wordpress-react-starter-kit-a61e2633c48c, you mentioned being able to run this on now.sh. Any tips on making that work?

When I attempt to run now from the root directory, I get the following output:

12/11 08:04 AM (12m)
npm install
12/11 08:04 AM (12m)
βœ“ Using "yarn.lock"
12/11 08:04 AM (12m)

> [email protected] preinstall /home/nowuser/src
> chmod +x install.sh && ./install.sh
12/11 08:04 AM (12m)

Sorry, this installation script only works on Mac OS X and Ubuntu Linux. Looks like your operating system is linux-musl.

TypeError: Cannot read property 'rendered' of undefined

When I was change likes pages names to like Home, About, Blog Contact page's. I'm getting this error message that said. I have not touch index.js but only WP Back-end.

TypeError: Cannot read property 'rendered' of undefined
    at Index.render (/Users/mirasmith/Desktop/wp__ireconcile/frontend/pages/index.js:59:13)
    at resolve (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2149:18)
    at ReactDOMServerRenderer.render (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2260:22)
    at ReactDOMServerRenderer.read (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2234:19)
    at renderToString (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2501:25)
    at renderPage (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/next/dist/server/render.js:174:26)
    at Function.getInitialProps (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/next/dist/server/document.js:83:25)
    at _callee$ (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/next/dist/lib/utils.js:36:30)
    at tryCatch (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/next/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/Users/mirasmith/Desktop/wp__ireconcile/frontend/node_modules/next/node_modules/regenerator-runtime/runtime.js:299:22)```

New feature: Configurable environment URLs

Allowing configurable URLs for production/development environments using something like dotenv could help a ton, specifically when deploying the applications. A few hardcoded localhost URLs are still in place.

Robo no longer on brew; update install.sh

Ran install, then...

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Debugged for hrs. I was convinced it was the mysql install and it seemed so because it would not run with out mysqld --skip-grant-tables.

However once I did manage to get it to run localhost:8080/wp-admin/ threw an error:
Warning: require_once(index.php): failed to open stream: No such file or directory in /private/var/folders/ss/k91_63kd68vdbby1c038f4z00000gp/T/wp-cli-router.php on line 111

I began to uninstall all deps from the install.sh. This is when I noticed that homebrew/php/robo was not installed at all. After some researching I found that the formula had been deprecated on brew and is only avail as direct download and install from robo.

Note: In order to install the robo.phar on my mac I did hold cmd + r at boot time and launch the terminal then run csrutil disable and reboot. Other wise moving the robo file to usr/bin was denied by the OS.

Hope this saves others some time & hopefully you can update the install.sh.

feat: make API endpoint configurable

Currently in the frontend JS, localhost:8080 is hardcoded as the API endpoint. Let's make this configurable as a buildtime/runtime environment variable.

Previewing posts

Is there a way to preview posts as you are creating/editing them from the WP dashboard?

Frontend: CSS does not get applied when routing

Styles don't get applied when routing to other pages that are styled, tried with both styled jsx and sass. I also tried with a fresh isntall, same thing there. Anyone that can look into it please?

ERROR 3009 (HY000) at line 1: Column count of mysql.user is wrong. Expected 45, found 43. Created with MySQL 50619, now running 50718.

During install I get a number of errors, starting here:

This will replace your current WordPress install. Are you sure you want to do this? (yes/no) [no]:
 > yes

 [Exec] Running mysql -uroot -proot -h 0.0.0.0 -e 'create user if not exists wp_headless'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 3009 (HY000) at line 1: Column count of mysql.user is wrong. Expected 45, found 43. Created with MySQL 50619, now running 50718. Please use mysql_upgrade to fix this error.
 [Exec]  Exit code 1  Time 0.093s

API POST request Unauthorized

I tried and create a WP User in the React structure using WP REST API endpoints. I get an Unauthorized 401 Error Code. See screenshot below.

capture d ecran 2017-12-22 a 01 16 48

Why is this happening? How to fix it?

Thanks.

babel-loader - You may need an appropriate loader to handle this file type.

Hey guys,

I'm trying something very basic, to import a css file in a component like this :
import './style.css'
The file style.css exist and is in the same folder as the component js file.
I already did that in other react web app but first time using the headless-wp-starter.

I get this error :

image

Any idea ?

Most of the fix for this issue that i found is to custum the babel loader but i didn't how to do that with this starter 'cause there is no webpack.babel.config.js or something like this

Ubuntu/Windows error starting backend: No such file or directory in /tmp/wp-cli-router.php

Hello,

I have been getting the following error when i attempt to yarn start.

PHP Warning: require_once(index.php): failed to open stream: No such file or directory in /tmp/wp-cli-router.php on line 111

PHP Fatal error: require_once(): Failed opening required 'index.php' (include_path='.:/usr/share/php') in /tmp/wp-cli-router.php on line 111

I am using Ubuntu on Windows.

Any Idea why I would get this error?

Backend Wordpress: Starting up Wordpress Backend getting error Messages.

I'm just started working with postlight getting this error whenever I start up the WP server. I might have missed a step. Could someone guide me step by step through the repo an again sometimes miss leading? @#



FetchError: invalid json response body at http://localhost:8080/wp-json/menus/v1/menus/header-menu reason: Unexpected token < in JSON at position 0
    at /Users/brandonpowell/headless-wp-starter/frontend/node_modules/node-fetch/lib/body.js:48:31 
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)```




```Warning: require_once(index.php): failed to open stream: No such file or directory in /private/var/folders/62/rvytymts561_lt66mbcb_c7m0000gn/T/wp-cli-router.php on line 111

Fatal error: require_once(): Failed opening required 'index.php' (include_path='.:') in /private/var/folders/62/rvytymts561_lt66mbcb_c7m0000gn/T/wp-cli-router.php on line 111```




```Not Found
The requested resource / was not found on this server.```

404 when hitting refresh

After getting everything up and running, I get a 404 on every page after I hit refresh and server rendering kicks in. The console gives me the following error (in this case on the sample page):

Page does not exist: /page/sample-page
Error: Page does not exist: /page/sample-page

Frontend: Trying to mimic wordpress page templates

Loving this starter so far! I've run into an issue I can't seem to solve and thought i'd throw it out here to see if anybody had an idea of how to achieve this.

What i'm looking to do, is mimic Wordpress's page template system in a way so that any post/page will use the pages/post.js file unless I want to have a different layout for say a /plans route. I would be able to put in a pages/plans.js file and tell the router to use that file instead of the pages/post.js file.

currently, i've modified the ./server.js file routes like this

server.get("/category/:slug", (req, res) => {
      const actualPage = "/category"
      const queryParams = { slug: req.params.slug }
      app.render(req, res, actualPage, queryParams)
    })

    server.get("/_preview/:id/:wpnonce", (req, res) => {
      const actualPage = "/preview"
      const queryParams = { id: req.params.id, wpnonce: req.params.wpnonce }
      app.render(req, res, actualPage, queryParams)
    })

    server.get("/:slug", (req, res) => {
      const actualPage = getPageTemplate(req.params.slug)
      const queryParams = { slug: req.params.slug, apiRoute: "post" }
      app.render(req, res, actualPage, queryParams)
    })

    server.get("*", (req, res) => {
      return handle(req, res)
    })

so my /:slug route is working fine, when i navigate around it uses the pages/post.js file, and the index route uses pages/index.js. I've also added const actualPage = getPageTemplate(req.params.slug) which is simple a switch statement against the slug which looks like

module.exports = slug => {
  switch (slug) {
    case 'plans':
      return '/plans'
    default :
      return '/post'
  }
}

now this actually works when i first load the website. If i go to localhost:3000/plans then it loads the pages/plans.js file and loads up my custom template. Cool! Server side routing works, but the problem comes when i navigate away and back to /plans, the client side routing loads up pages/post.js.

So, does anybody have any idea where I am going wrong here? What would I need to do in order to get that /plans route to always use pages/plans.js. Any advice is greatly appreciated!

Backend yarn start: unexpected error occurred: "Command "start" not found."

getting an error when using the above and getting the following error

yarn install && yarn start
yarn install v1.5.1
[1/4] πŸ” Resolving packages...
success Already up-to-date.
✨ Done in 0.70s.
yarn run v1.5.1
error An unexpected error occurred: "Command "start" not found.".
info If you think this is a bug, please open a bug report with the information provided in "/Users/willmartin/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Ive attached the error log for more details. The package.json file looks to be correct but not sure what the issue is

Thanks for any help and for building an awesome tool!

yarn-error.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.