diff --git a/index.js b/index.js index c863900a7367bfcfccfc512f04104d3354e3baac..339f9390bacb6dabd6f7d428724dec1cf7e68677 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,37 @@ '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 diff --git a/package.json b/package.json index d773b163368a398cce0cef9d9baf4aefb87f1171..f4fc3fb091cdf59541e812c351183c6c507cb46d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ }, "dependencies": { "express": "*", - "wpapi": "*" + "wpapi": "*", + "express-handlebars": "*" }, "repository": { "type": "git", diff --git a/render/index.handlebars b/render/index.handlebars new file mode 100644 index 0000000000000000000000000000000000000000..b32ecef5e03972bce037ce0614251977dc268e56 --- /dev/null +++ b/render/index.handlebars @@ -0,0 +1 @@ +{{!< main}} \ No newline at end of file diff --git a/render/templates/main.handlebars b/render/templates/main.handlebars new file mode 100644 index 0000000000000000000000000000000000000000..0afa120be6aa8c590fac72e3771d40e68ae2cad9 --- /dev/null +++ b/render/templates/main.handlebars @@ -0,0 +1,7 @@ + + + + + + +