node.js serve a wordpress blog - wordpress

I am using node.js on my rackspace server to serve my various applications. (Using node-http-proxy).
However, i would like to start a wordpress blog. The only way to serve the blog is via apache (or nginx).
Is there a way to server my wordpress blog from a node.js application itself?

You need some server running to execute the PHP. Node is JavaScript.
Whether that's apache, or nginx/php-fpm or just php-fpm, you need something to actually run the wordpress code, then use the same proxying system you are using now.

One option is to continue to use Wordpress as you normally do, but instead of writing the templates to output HTML, you make them output JSON. With this minor trick, you suddenly have created your own API to output your wordpress content. In contrast with the modules that expose wordpress complete set of methods, this will create your very specific output, tailored after your needs.
To consume your JSON output, you set up a small nodejs server that forwards each call directly to your Wordpress solution, takes the response (JSON) and merges it with your html using whatever javascript template engine you like. You also gain speed, since you can cache the JSON result pretty easily on the node side, and control.
I've written a blogpost about this if you like to read more, and also created a nodejs express middleware to help setting up the node side.
http://www.1001.io/improve-wordpress-with-nodejs/

You can try express-php-fpm package.
It combines Express (Node.js server) and FastCGI gateway to serve php requests.

I found this node module while searching for Wordpress + Node:
https://github.com/scottgonzalez/node-wordpress
I haven't tried it, though, but if you know what you're doing you might want to give it a go.

I recently needed to get a server within an electron app to serve PHP.
I started with grunt-php by Sindre Sorhus. The main change I made was to remove the code that kills the server process when grunt is done, instead instantiating the PHP class from JS and calling the process as needed.
Ultimately, it was very easy to adapt grunt-php to enable PHP on a node.js server.

WordPress now has an "official" (to be precise: open source, under Automattic's github repo) way to do this: wpcom.js. From that github page:
Official JavaScript library for the WordPress.com REST API. Compatible with Node.js and web browsers.
The essence is to call the WordPress REST API from JS.

Related

Change server in all URLs

Using PAW and I have setup a bunch of test URLs for my API server. No I want to repeat all those URLs on my dev and staging servers.
Is it possible to do a search and replace on the server domain name to recreate the same tests for each server?
Unfortunately, there's no way yet in Paw to edit requests in batch.
The recommended way for fields that are likely to change (e.g. server hostname / base URL) is to set them in environment variables. See this documentation article: https://paw.cloud/docs/environments/environments-reusable-presets
Note: batch editing is for sure something that will come in future versions.

How to use/integrat the Piwik tracking API in Symfony 2 without JavaScript

I would like to track the users on my Symfony 2.7 page using Piwik.
Piwiks default tracking option is the integration of a small JavaScript into the webpage, e.g. with the page footer. Of course this could easily be done by adding the code to the base Twig template.
However I would like to avoid the usage of JavaScript. My Symfony page and the Piwik page both run on the same server. Actually I am surprised that letting the client communicate with Piwik (over Javascript) is the recommended option instead of a direct way to let the webpage server talk to Piwik.
I think the Tracking HTTP API and the PHP Client are what I am looking for. However I am not sure on how to integrate this into Symfony.
I managed to connect my Symfony page with Piwik, however I wonder if this the right/best way to do it:
Used composer require "piwik/piwik-php-tracker" to add the PHPTracker to my Symfony project
Added a new Service that is responsible to create and manage a PiwikTracker object. The Service makes different methods of the Tracker, e.g. doTrackPageView() available to the rest of the project.
Added a new Twig function which uses the Service to trigger the doTrackPageView() method.
Added a call to this function to my base template
This works fine: Page views are correctly reported to Piwik and recorded without any problem. Of course I could easily add other methods to track events, actions, etc.
But: I am really surprised that I could not find any ready-to-use solution for this. Did I miss anything or is this the indented way to use Piwik with Symfony?

A Way to Load CSS link[rel=preload] Method with Yeoman Webapp

Is there a way to use the new standard link[rel=preload] with yo webapp so grunt serve will load the CSS file ?
Example:
<link rel="preload" href="path" as="style" onload="this.rel='stylesheet'">
I assume that by "so grunt serve will load the CSS file" you mean that the http server started by the grunt task will preemptively serve (push) the css file in addition to serving the http file, therefore saving time?
Unfortunately getting this to work is not currently as trivial as setting up grunt serve in the right way. Push operations is an Http/2 feature, and the server used by grunt serve by default is the stock node one, which is Http/1.1 only.
If you feel like helping yourself, and also contributing back to the community, you could author a project that wraps or forks 'grunt-serve' and replaces require('http') with something like this as the http server, while also having either a server-side parser examining the pages served looking for 'preload' attributes, or some other way of signifying to your plugin what files need to be served alongside each page.
I don't know of any browsers that actually support link[rel=preload] as of now nor do I even see it listed on caniuse.com.
This feature is really a browser implementation feature rather than something controlled by any application or server code so unfortunately, unless you're writing a browser, I think the answer is no, there is no way to use the new standard. We'll just need to wait for it to be adopted and implemented by the browsers.

Is moving a CSS file between .NET servers difficult?

Here's the rundown:
- We have a web site built with a commercial CMS (Sitefinity)
- The web site is .NET
- We have a test server and the live server set up for development (HTML, CSS, JavaScript).
I'm not a .NET programmer, but I work on a lot of frontend work. My question is this:
When I make CSS changes on the test server, is it normal practice for the entire web site to be "pushed" over to the live server? In other words, can I not just move over the CSS file from development to the live server? (It does not work when I do this.)
I ask this because every time CSS changes are made, the entire web site has to shutdown for 10-20 minutes to "push" the entire development to the live server. This seems like an unusual practice for something so small as making a few CSS changes, and it heavily slows down my work. Shutting down an entire web site to publish one basic CSS file just seems unreasonable of a service.
Can someone please educate me about your processes for .NET and CSS changes? What are the best practices in the industry? I would like to better my understanding of this.
Thank you. Your insight is appreciated.
We use Sitefinty as well and you can just copy or FTP the CSS file or files instead of redeploying the entire site. I like to use Beyond Compare.
We have some ways to push the changes on our development server to live server using sitefinity:
We can choose synchronization option in sitefinty, using that we can push content and all from one server to other server.
http://www.sitefinity.com/documentation/gettingstarted/getting-started-synchronizing-data-between-two-servers
You are doing updation on css files only then need not to push all code every time, might be after doing changes you are not able to see reflection, in that case please publish the page once and you can see reflection.
Please let me know if you want to know more.
It's possible there is some sort of caching going on. perhaps you can check the settings for static content with your host or in IIS to see when static files like css expire.
In addition you can restart Sitefinity by going to Administration Settings > Basic > Languages and clicking Save (or installing the Falafel Dashboard which has a handy restart button you can put on the home page)
Restarting the site should clear the cache and show you the changes. I hope this is helpful!

How to PUT and POST image files to Apache2 using vhosts? (without PHP)

I want to simply POST and PUT image files to a server test.com, using apache2. This should result in storing the image file at the desired location. Lets say /srv/web/images/
What would be a working vhost configuration? Are there any modules that need to be activated? I am using apache2 on an ubuntu 12.04 server.
I think by default this is disabled in apache for obvious resons, nobdoy should be able to write to a server in the default configuration.
I want to simply secure it with http auth ("user1" / "pass1").
All the documentation and questions I find deal with PHP, but I thought should be possible using simply a REST URI and apache2 without PHP or cgi or a C program.
(Note: I am interessted in a solution without webdav (but I am not sure if the webdav module supports HTTP PUT which would be OK). And this question has got nothing to with forms or browsers, As an example the upload could use the program curl.)
Update: I found this message:
http://mail-archives.apache.org/mod_mbox/ant-ivy-user/201004.mbox/%3C4BBCA487.8000401#nitido.com%3E
It seems there once was a module mod_put, which is no longer in the repos of ubuntu. And that webdav has built in the functionality of PUT and DELETE.
If so, I am still unable to understand how to do the right VHOST configuration for simple FILE PUT operations.
I think nowadays for this kind of stuff you configure apache with WebDAV.

Resources