Commit fc783208 authored by Erick Hitter's avatar Erick Hitter

Handlebars for templating

parent 6e8cda57
'use strict';
var express = require( 'express' );
var wpapi = require( 'wpapi' );
var app = express();
// Libraries and other setup
var express = require( 'express' );
var wpapi = require( 'wpapi' );
var handlebars = require( 'express-handlebars' );
var app = express();
// Only one route
app.set( 'view engine', 'handlebars' );
app.engine( 'handlebars', handlebars( {
defaultLayout: __dirname + '/render/templates/main.handlebars',
partialsDir: __dirname + '/render/partials',
layoutsDir: __dirname + '/render/templates'
} ) );
app.set( 'views', __dirname + '/render' );
var domains = [
'https://ethitter.com',
'https://erick.blog',
'https://i.ethitter.com'
];
// Rendering
app.get( '/', function( req, res ) {
res.send( 'Hello World' );
res.render( 'index', domains );
} );
// Get some data
app.get( '/api', function( req, res ) {
res.status( 400 ).send( { error: 'Must specify a domain!' } );
} );
app.get( '/api/:domain', function( req, res ) {
res.json( { 'd': req.params.domain } );
} );
// Listen on some random, unused port
......
......@@ -15,7 +15,8 @@
},
"dependencies": {
"express": "*",
"wpapi": "*"
"wpapi": "*",
"express-handlebars": "*"
},
"repository": {
"type": "git",
......
{{!< main}}
\ No newline at end of file
<!DOCTYPE>
<html>
<head>
<title></title>
</head>
<body></body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment