Titan
Titan is the full user-facing front end for your Tilas platform which is built completely on the Spartan API. It can be thought of as the front-end blog which your users will interact with. It's a fully responsive front-end that is highly customisable using environment variables and a configuration file. On top of standard blogging features (e.g. articles, posts, images, tagging, authors etc), it also comes with cool features like social media share links, adsense, google analytics and an automatic sharing (AutoShare) feature that will manage your facebook sharing on a schedule (when configured via the Lantern CMS).
Settings up Titan on your Server:
Prerequisites:
- Spartan API Layer: You need your Spartan API layer up and running before you can continue with your Titan installation. Your Spartan API needs to be accissible via a public URL like so "http://spartan.yourdomain.com".
- Facebook Page/App: (This is optional, but…) to get the full benefits of Titan, "pair" it with a Facebook Page/App. To do this, set up a Facebook Page and then register a new Facebook App for your page. You can then get a Facebook App's Client ID and Secret. These will be used to power the "AutoShare" feature of your blog/site.
Titan Software Installation (Source Setup)
For below example, let assume our new site is called "funnycatsblog"
- Create a new folder and name it funnycatsblog
- Inside the funnycats folder, Clone / Copy the latest Titan project source
- To install all dependencies, run:
npm install
Environment Variables:
Environment Variables - Development: Open "scripts/development.sh" and enter your details from the prerequisites section to the NodeJS environment variables. Specifically SPARTAN_ROOT, FB_CLIENT_ID and FB_CLIENT_SECRET. You can then fill up the remaining variables as needed.
Environment Variables - Staging/Production: You can edit the "scripts/staging.sh" or "scripts/production.sh" with your staging/production details or if you use Heroku or Docker/Dokku you will need to export these vars into your server as per their required way.
Export your environmental variable into your current session. run:
. scripts/development.sh
Site Specific Configuration:
- The Environment Variables will power your features and content layer, but to configure your blog/site's look-and-feel you can edit the "config/default.json" file. The "site" section is used to customise the data model for your content, use specific category names, enable and disable certain features, set meta data for your pages, configure your Ads, setup your social networking page links and sharing features, set up Google Analytics etc.
Updating server ports (optional step; if not done it will default to port 3000):
- Open your config/default.json, config/development.json, config/staging.json, config/production.json files and update any specific ports if needed.
- Or export a PORT environmental variable to overwrite all of these.
Start your app:
Firstly your would need to start your Spartan layer after which you can launch your Titan site/blog like so:
npm start
Open your browser and navigate to app url:port, e.g. http://localhost:3000
Site Specific Styling:
- Now that your can see what your default front-end looks like, you might want to make some site specific style changes. You can do this by editing the "public/css/main.css" file and scrolling down to the end of the file to the "SITE SPECIFIC OVERRIDES" section where you can place your CSS code.
TITAN IS NOW UP AND READY TO SERVE FOR PUBLIC ACCESS. YOUR NEXT STEP WOULD BE TO SETUP LANTERN.
Development Tips
Debugging: To effectively debug your nodeJS app, I prefer to use node-inspector which pretty much lets your perform JavaScript debugging like you are used to in Chrome Dev Tools. To debug this app using node-inspector do this:
$ node --debug app.js // start your app in debug mode
$ node --debug-brk app.js // or to to pause script on first line do this
Now:
$ node-inspector & //launch the inspector
Read more here : https://greenido.wordpress.com/2013/08/27/debug-nodejs-like-a-pro/
Logging This app uses Bunyan for logging. This is a very advanced logging system that stores machine readable logs if needed. When the app runs, user friendly logs are spit out on the console to log our all trace (info and above), but it can be setup to only log to a file instead of the console or log on warns and above. There are more advanced use cases as well.
To prob apps in production, more here : https://www.joyent.com/blog/node-js-in-production-runtime-log-snooping
Read more here : https://github.com/trentm/node-bunyan