diff --git a/bin/www.js b/bin/www.js index 2b23ddd4..6ab1f61d 100644 --- a/bin/www.js +++ b/bin/www.js @@ -10,5 +10,6 @@ var instagram = require("../instagram"); db.init(config.db.uri) //.then(instagram) .then(function () { - server(config.port); + var app = server(); + app.listen(config.port); }); \ No newline at end of file diff --git a/config.js b/config.js index adba48cb..cd54ad3d 100644 --- a/config.js +++ b/config.js @@ -1,4 +1,5 @@ var fs = require("fs"); +var path = require("path"); const MENU = require("./models/menu.json"); const team = require("./models/team"); @@ -9,40 +10,42 @@ const schedule = require("./models/schedule"); var privateFile = process.env["PRIVATE"] || "private.json"; var privateData = JSON.parse(fs.readFileSync(privateFile, "utf-8")); +var index_file = process.env["INDEX"] || "templates/main.html"; + var config = { - defaultIndex: "/templates/index.html" || process.env["INDEX"], - port: process.env["PORT"] || 3000, - pub: "./", - data: { - menu: MENU, - documents: document.docs, - team: team.team, - courses: course.courses - }, + defaultIndex: path.join(__dirname, index_file), + port: process.env["PORT"] || 3000, + pub: "./", + data: { + menu: MENU, + documents: document.docs, + team: team.team, + courses: course.courses + }, - db: { - uri: "mongodb://localhost:27017/hudozka" - }, + db: { + uri: "mongodb://localhost:27017/hudozka" + }, - prerender: { - prerender: "http://service.prerender.io/", - prerenderToken: "", - protocol: "http", - host: "art.shlisselburg.org" - }, + prerender: { + prerender: "http://service.prerender.io/", + prerenderToken: "", + protocol: "http", + host: "art.shlisselburg.org" + }, - instagram:{ - default_user: "hudozka", - tag_callback: "http://art.shlisselburg.org/instagram/callback/11", - client_id: "", - client_secret: "", - redirect_uri: "http://art.shlisselburg.org/instagram/auth/callback", - tags: ["shlb_hudozka"] - } + instagram: { + default_user: "hudozka", + tag_callback: "http://art.shlisselburg.org/instagram/callback/11", + client_id: "", + client_secret: "", + redirect_uri: "http://art.shlisselburg.org/instagram/auth/callback", + tags: ["shlb_hudozka"] + } }; module.exports = Object.keys(privateData) - .reduce(function (config, key) { - config[key] = privateData[key]; - return config; - }, config); \ No newline at end of file + .reduce(function (config, key) { + config[key] = privateData[key]; + return config; + }, config); \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index dbe2d91e..d33de380 100644 --- a/routes/index.js +++ b/routes/index.js @@ -17,18 +17,16 @@ function accepts(routes, def) { if (types.length) { var type = types[0]; yield routes[type].apply(this, arguments); - } else if(def){ + } else if (def) { yield def; - }else{ + } else { this.status = 406; } }; } function index(filename) { - if (!filename){ - filename = path.join(__dirname, "..", config.defaultIndex); - } + if (!filename) filename = config['defaultIndex']; return function *() { this.type = "text/html"; diff --git a/server.js b/server.js index 152df729..82b8236a 100644 --- a/server.js +++ b/server.js @@ -28,20 +28,20 @@ app.use(serve(path.join(__dirname, "templates"))); app.use(helmet.defaults()); app.use(function *(next) { - var q = this.query; - this.query = Object.keys(q) - .reduce(function (q, key) { - var v = q[key]; - if(v === "true"){ - v = true; - }else if(v === "false"){ - v = false; - } - q[key] = v; - return q; - }, q); + var q = this.query; + this.query = Object.keys(q) + .reduce(function (q, key) { + var v = q[key]; + if (v === "true") { + v = true; + } else if (v === "false") { + v = false; + } + q[key] = v; + return q; + }, q); - yield next; + yield next; }); app.use(route.get("/", routes.index())); @@ -49,33 +49,18 @@ app.use(route.get("/team", routes.index())); app.use(route.get("/docs", routes.index())); app.use(route.get("/document/:doc", routes.index( - path.join(__dirname, "templates/document.html") + path.join(__dirname, "templates/document.html") ))); require("./routes/schedule")(app); require("./routes/news")(app); require("./routes/gallery")(app); -require("./routes/404")(app); - require("./instagram/router")(app); require("./instagram/io")(app); -if (process.env["NODE_ENV"] === "development") { - app.use(route.get("/debug", function *() { - var out = {}; - out.ip = this.ip; - out.host = this.host; - out.headers = this.headers; - out.protocol = this.protocol; - out.query = this.query; - out.url = this.url; - - this.type = "application/json"; - this.body = out; - })); -} +require("./routes/404")(app); module.exports = function (port) { - app.listen(port); + return app; }; diff --git a/templates/index-dev.html b/templates/main-dev.html similarity index 91% rename from templates/index-dev.html rename to templates/main-dev.html index d790187e..7a25ea3c 100644 --- a/templates/index-dev.html +++ b/templates/main-dev.html @@ -29,15 +29,12 @@
- + diff --git a/templates/index.html b/templates/main.html similarity index 100% rename from templates/index.html rename to templates/main.html