2013-05-11 20:44:25 +04:00
|
|
|
// # Ghost main app file
|
|
|
|
|
2013-05-17 01:16:09 +04:00
|
|
|
/*global require, __dirname */
|
2013-05-11 20:44:25 +04:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Module dependencies.
|
|
|
|
var express = require('express'),
|
|
|
|
admin = require('./core/admin/controllers'),
|
|
|
|
frontend = require('./core/frontend/controllers'),
|
2013-05-16 15:21:13 +04:00
|
|
|
api = require('./core/shared/api'),
|
2013-05-11 20:44:25 +04:00
|
|
|
flash = require('connect-flash'),
|
|
|
|
Ghost = require('./core/ghost'),
|
|
|
|
I18n = require('./core/lang/i18n'),
|
2013-05-19 02:03:57 +04:00
|
|
|
helpers = require('./core/frontend/helpers'),
|
2013-05-11 20:44:25 +04:00
|
|
|
|
|
|
|
// ## Variables
|
2013-05-19 02:03:57 +04:00
|
|
|
auth,
|
|
|
|
|
2013-05-17 01:16:09 +04:00
|
|
|
/**
|
|
|
|
* Create new Ghost object
|
|
|
|
* @type {Ghost}
|
|
|
|
*/
|
2013-05-11 20:44:25 +04:00
|
|
|
ghost = new Ghost();
|
|
|
|
|
|
|
|
ghost.app().configure('development', function () {
|
|
|
|
ghost.app().use(express.favicon(__dirname + '/content/images/favicon.ico'));
|
|
|
|
ghost.app().use(express.errorHandler());
|
|
|
|
ghost.app().use(I18n.load(ghost));
|
|
|
|
ghost.app().use(express.bodyParser());
|
|
|
|
ghost.app().use(express.cookieParser('try-ghost'));
|
|
|
|
ghost.app().use(express.session({ cookie: { maxAge: 60000 }}));
|
|
|
|
ghost.app().use(flash());
|
|
|
|
ghost.app().use(ghost.initTheme(ghost.app()));
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup login details
|
|
|
|
* p.s. love it.
|
|
|
|
*
|
|
|
|
* @type {*}
|
|
|
|
*/
|
|
|
|
auth = express.basicAuth('ghostadmin', 'Wh0YouGonnaCall?');
|
|
|
|
|
|
|
|
helpers.loadCoreHelpers(ghost);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API routes..
|
2013-05-16 15:21:13 +04:00
|
|
|
* @todo auth should be public auth not user auth
|
2013-05-11 20:44:25 +04:00
|
|
|
*/
|
2013-05-16 15:21:13 +04:00
|
|
|
ghost.app().get('/api/v0.1/posts', auth, api.requestHandler(api.posts.browse));
|
|
|
|
ghost.app().get('/api/v0.1/posts/:id', auth, api.requestHandler(api.posts.read));
|
|
|
|
ghost.app().post('/api/v0.1/posts/create', auth, api.requestHandler(api.posts.add));
|
|
|
|
ghost.app().put('/api/v0.1/posts/edit', auth, api.requestHandler(api.posts.edit));
|
|
|
|
ghost.app()['delete']('/api/v0.1/posts/:id', auth, api.requestHandler(api.posts.destroy));
|
2013-05-11 20:44:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Admin routes..
|
|
|
|
* @todo put these somewhere in admin
|
|
|
|
*/
|
|
|
|
ghost.app().get('/ghost/editor/:id', auth, admin.editor);
|
|
|
|
ghost.app().get('/ghost/editor', auth, admin.editor);
|
|
|
|
ghost.app().get('/ghost/blog', auth, admin.blog);
|
|
|
|
ghost.app().get('/ghost/settings', auth, admin.settings);
|
|
|
|
ghost.app().get('/ghost/debug', auth, admin.debug.index);
|
|
|
|
ghost.app().get('/ghost/debug/db/delete/', auth, admin.debug.dbdelete);
|
|
|
|
ghost.app().get('/ghost/debug/db/populate/', auth, admin.debug.dbpopulate);
|
2013-05-19 02:03:57 +04:00
|
|
|
ghost.app().get(/^\/(ghost$|(ghost-admin|admin|wp-admin|dashboard|login)\/?)/, auth, function (req, res) {
|
|
|
|
res.redirect('/ghost/');
|
|
|
|
});
|
|
|
|
ghost.app().get('/ghost/', auth, admin.index);
|
2013-05-11 20:44:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Frontend routes..
|
|
|
|
* @todo dynamic routing, homepage generator, filters ETC ETC
|
|
|
|
*/
|
|
|
|
ghost.app().get('/:slug', frontend.single);
|
|
|
|
ghost.app().get('/', frontend.homepage);
|
|
|
|
|
|
|
|
|
|
|
|
ghost.app().listen(3333, function () {
|
|
|
|
console.log("Express server listening on port " + 3333);
|
|
|
|
});
|
2013-05-17 01:16:09 +04:00
|
|
|
// }, function (e) {
|
|
|
|
// console.log(e.toString());
|
|
|
|
// }).then(null, function (e) {
|
|
|
|
// console.log(e.stack);
|
|
|
|
// });
|
2013-05-11 20:44:25 +04:00
|
|
|
}());
|