Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

Commit

Permalink
Adding application startup files
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypee committed Apr 26, 2012
1 parent a0798c5 commit 84f725d
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
@./node_modules/.bin/mocha --bail

.PHONY: test
164 changes: 164 additions & 0 deletions app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@

#
# ._ _ _ _
# | \ | | | (_)
# | \| | ___ __| |_ _______
# | . ` |/ _ \ / _` | |_ / _ \
# | |\ | (_) | (_| | |/ / __/
# \_| \_/\___/ \__,_|_/___\___|
#
# v0.1.0
#
# Nodize CMS by Hypee (c)2012 (www.hypee.com)
# Released under MIT License
#
#

#
# Retrieve database configuration from json setting file
#
fs = require 'fs'
path = require 'path'

nodizeSettings = require 'nconf'
global.__nodizeSettings = nodizeSettings

#
# If a local file exists we use it, else we fallback on the regular settings file
#
if path.existsSync( 'settings/nodize.local.json')
nodizeSettingsFile = 'settings/nodize.local.json'
else
nodizeSettingsFile = 'settings/nodize.json'

nodizeSettings.add( 'nodize', {type: 'file', file:nodizeSettingsFile } )

#
# Starting profiler if specified in settings
#
require("nodetime").profile() if nodizeSettings.get("nodetime_profiler")

everyauth = require "everyauth"
nodize = require('zappa').app ->

@use bodyParser:{ uploadDir: __dirname+'/uploads' } # Needed to get POST params & handle uploads

#@use 'debug' # Connect debug middleware, uncomment to activate
#@use 'responseTime' # Display response time in HTTP header, uncomment to activate



#
# Storing application path & theme path for later use in modules
#
global.__applicationPath = __dirname
global.__nodizeTheme = nodizeSettings.get( "theme" )
global.__sessionSecret = nodizeSettings.get( "session_secret" )
global.__adminPassword = nodizeSettings.get( "admin_password" )


global.__default_lang = 'en'

# Allow to request static content from /public folder of current theme
@use 'static': __dirname + "/themes/" + __nodizeTheme + "/public"

@use 'cookieParser'
@use 'cookieDecoder'

# Including Nodize MySQL/SQLite session store (use same database dialect than specified in config file)
@include './modules/nodize-sessions/module_nodize-sessions.coffee'

#
# Logging connexions to /logs/access.log file
#
logFile = fs.createWriteStream('./logs/access.log', {flags:'a'})
#@use 'logger':{stream:logFile}

#
# Defining views folder, in current theme
#
@set 'views' : __dirname + "/themes/" + __nodizeTheme + "/views"

#
# Event engine
#
EventEmitter = require( "events" ).EventEmitter
global.__nodizeEvents = new EventEmitter();

# Defining helpers container
@helpers = {}

# Including backend/administration module
@include './modules/backend/module_backend.coffee'

# Must be the last module, it's handling the "catch all" router
@include './modules/ionize/module_ionize.coffee'

# Retrieving helpers defined in modules, making them available to views
helpers = @helpers



#
# Desactivating socket.io console debug messages
#
nodize.io.set 'log level', 1

#
# Defining the port we listen on
# Default to 3000
#
port = process.env.PORT or 3000


#
# Start the server
#

cluster = require 'cluster'

numCPUs = require('os').cpus().length

# Cluster mode is currently disabled
numCPUs = 0

if cluster.isMaster
console.log "ZappaJS", nodize.zappa.version, "orchestrating the show"

console.log """
._ _ _ _
| \\ | | | (_)
| \\| | ___ __| |_ _______
| . ` |/ _ \\ / _` | |_ / _ \\
| |\\ | (_) | (_| | |/ / __/
\\_| \\_/\\___/ \\__,_|_/___\\___|
"""
console.log "listening on port",port

console.log "using",numCPUs," CPU(s)" if numCPUs>0

#
# In development mode, set numCPU to 0 to allow clean automatic reload when using run.js
#
if numCPUs>0
# Fork workers.
for i in [1..numCPUs]
cluster.number = i
cluster.fork()

cluster
.on 'death', ->
console.log 'worker ' + worker.pid + ' died'
else
nodize.app.listen( port )

else
# Worker processes have a Express/Zappa/Nodize server.

console.log "Cluster", cluster.pid, "started" if cluster.pid # pid seems to be available in node.js >= 0.6.12
nodize.app.listen( port )




1 change: 1 addition & 0 deletions devStart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development nodemon -w settings -w modules -w app.coffee
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "nodize",
"description": "Nodize CMS",
"author": "Hypee & Partikule <contact@nodize.com>",
"homepage": "http://www.nodize.com",
"version": "0.1.0",
"main": "app.coffee",
"dependencies": {
"connect":"1.8.6",
"sequelize": "1.3.7",
"coffee-script": "1.2.0",
"coffeekup": "0.3.1",
"nconf": "0.5.1",
"socket.io": "0.8.7",
"socket.io-client":"0.8.7",
"imageinfo":"1.0.4",
"validator":"0.4.5",
"zappa":"https://github.com/nodize/zappa/tarball/master"
},
"devDependencies":
{
"mocha" : "1.0.0",
"zombie" : "0.12.15"
},
"scripts":{
"test":"mocha"
},
"license":"MIT",
"engine": "node >= 0.4.6"
}
1 change: 1 addition & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=production nodemon -w settings -w modules -w app.coffee -w themes

0 comments on commit 84f725d

Please sign in to comment.