-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
freekode
committed
Jul 9, 2013
0 parents
commit be90b42
Showing
32 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/* | ||
*.log | ||
app/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module.exports= (grunt) -> | ||
grunt.initConfig | ||
pkg: grunt.file.readJSON 'package.json' | ||
clean: | ||
all: ['<%= pkg.config.compile.out %>/'] | ||
|
||
coffee: | ||
main: | ||
options: | ||
bare: true | ||
files: [ | ||
{ | ||
expand: true | ||
cwd: '<%= pkg.config.compile.in %>' | ||
src: ['**/*.coffee'] | ||
dest: '<%= pkg.config.compile.out %>' | ||
ext: '.js' | ||
} | ||
] | ||
|
||
yaml: | ||
package: | ||
options: | ||
ignored: /^_/ | ||
space: 2 | ||
files: [ | ||
{ | ||
expand: true | ||
cwd: '<%= pkg.config.compile.in %>' | ||
src: ['**/*.yaml', '**/*.yml'] | ||
dest: '<%= pkg.config.compile.out %>/' | ||
ext: '.json' | ||
} | ||
] | ||
|
||
copy: | ||
modules: | ||
files: [ | ||
{ | ||
expand: true | ||
cwd: '<%= pkg.config.compile.in %>' | ||
src: ['**/*.py', '**/*.sh'] | ||
dest: '<%= pkg.config.compile.out %>' | ||
} | ||
] | ||
static: | ||
files: [ | ||
{ | ||
expand: true | ||
cwd: '<%= pkg.config.compile.in %>/views' | ||
src: ['**/*', '!**/*.coffee', '!**/*.md'] | ||
dest: '<%= pkg.config.compile.out %>/views' | ||
} | ||
] | ||
readme: | ||
{ | ||
src: '<%= pkg.config.compile.in %>/readme.md' | ||
dest: '<%= pkg.config.compile.out %>/readme.md' | ||
} | ||
|
||
coffeelint: | ||
app: | ||
options: | ||
indentation: | ||
level: 'error' | ||
value: 4 | ||
line_endings: | ||
value: 'unix' | ||
level: 'error' | ||
max_line_length: | ||
level: 'warn' | ||
files: [ | ||
{ | ||
src: '<%= pkg.config.compile.in %>/**/*.coffee' | ||
} | ||
] | ||
|
||
|
||
|
||
|
||
grunt.loadNpmTasks 'grunt-contrib-clean' | ||
grunt.loadNpmTasks 'grunt-contrib-copy' | ||
grunt.loadNpmTasks 'grunt-contrib-coffee' | ||
grunt.loadNpmTasks 'grunt-yaml' | ||
grunt.loadNpmTasks 'grunt-coffeelint' | ||
|
||
grunt.registerTask 'default', ['clean', 'yaml', 'coffee', 'copy'] | ||
grunt.registerTask 'lint', ['coffeelint'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Config files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "apiserver", | ||
"version": "0.0.1", | ||
"private": true, | ||
"config": { | ||
"compile": { | ||
"in": "src/", | ||
"out": "app/" | ||
} | ||
}, | ||
"scripts": { | ||
"prestart": "grunt.cmd", | ||
"start": "cd app && npm start", | ||
"test": "grunt lint" | ||
}, | ||
"dependencies": { | ||
"express": "3.x", | ||
"express-namespace": "latest", | ||
"jade": "latest", | ||
"log": "latest" | ||
}, | ||
"devDependencies": { | ||
"grunt": "latest", | ||
"grunt-contrib-clean": "latest", | ||
"grunt-contrib-copy": "latest", | ||
"grunt-contrib-coffee": "latest", | ||
"grunt-yaml": "latest", | ||
"grunt-cli": "latest", | ||
"grunt-coffeelint": "latest" | ||
}, | ||
"engines": { | ||
"node": "~0.8.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# API-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Specification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
exports.config = -> | ||
passport = require 'passport' | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy | ||
|
||
|
||
|
||
strategyOptions = | ||
clientID: process.env.npm_package_config_auth_google_id | ||
clientSecret: process.env.npm_package_config_auth_google_secret | ||
callbackURL: process.env.npm_package_config_url + process.env.npm_package_config_auth_google_callback | ||
|
||
|
||
passport.serializeUser (user, done) -> | ||
done null, user.id | ||
|
||
|
||
passport.deserializeUser (obj, done) -> | ||
console.log 'DESER ', obj | ||
done null, obj | ||
|
||
|
||
# возвращаем стартегию и применяем в init функции модуля | ||
strategyGoogleOAuth = new GoogleStrategy strategyOptions, (token, tokenSecret, profile, done) -> | ||
console.log 'Google ', token, profile | ||
done null, profile | ||
|
||
|
||
passport.use(strategyGoogleOAuth) | ||
|
||
|
||
|
||
exports.login= (passport) -> | ||
passport.authenticate 'google', | ||
scope: [ | ||
'https://www.googleapis.com/auth/userinfo.profile' | ||
'https://www.googleapis.com/auth/drive.readonly' | ||
] | ||
|
||
|
||
|
||
exports.callback = (passport) -> | ||
passport.authenticate 'google', | ||
failureRedirect: '/gitweb/' | ||
successRedirect: '/' | ||
|
||
|
||
|
||
#middlware авторизирован ли наш пользователь | ||
exports.isAuth = (req, res, next) -> | ||
if req.isAuthenticated() | ||
next() | ||
else | ||
res.redirect '/' | ||
|
||
|
||
exports.isNoAuth = (req, res, next) -> | ||
if req.isUnauthenticated() | ||
next() | ||
else | ||
res.redirect '/' | ||
|
||
|
||
|
||
exports.logout= (req, res) -> | ||
req.logout() | ||
res.redirect '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
exports.all= (req,res) -> | ||
res.send 200 | ||
|
||
|
||
exports.add= (req,res) -> | ||
res.send 200 | ||
|
||
exports.one= (req,res) -> | ||
res.locals.points= [ | ||
{ | ||
lat: '54.4125994638497' | ||
lng: '22.0096868276596' | ||
date: '10.10.2010 15.55.64' | ||
geocode: 'Here' | ||
} | ||
{ | ||
lat: '54.117788' | ||
lng: '21.115577' | ||
date: '11.10.2010 15.55.64' | ||
geocode: 'I dunno' | ||
} | ||
{ | ||
lat: '54.887937' | ||
lng: '58.843558' | ||
date: '12.10.2010 15.55.64' | ||
geocode: 'Ok' | ||
} | ||
] | ||
res.render 'Car/one.jade' | ||
|
||
exports.change= (req,res) -> | ||
res.send 200 | ||
|
||
|
||
exports.delete= (req,res) -> | ||
res.send 200 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
exports.index= (req,res) -> | ||
#Mysql= require 'some-mapper-mysql' | ||
#my= new Mysql | ||
# host : 'sql2.freemysqlhosting.net' | ||
# user : 'sql29461' | ||
# password : 'fU3*pA9!' | ||
# database : 'sql29461' | ||
|
||
res.render 'Index/index.jade' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
exports.register= (req,res) -> | ||
res.send 200 | ||
|
||
|
||
exports.one= (req,res) -> | ||
res.send 200 | ||
|
||
|
||
|
||
exports.change= (req,res) -> | ||
res.send 200 | ||
|
||
|
||
exports.delete= (req,res) -> | ||
res.send 200 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports= (app) -> | ||
Index= require './Index/' | ||
Car= require './Car/' | ||
User= require './User/' | ||
Auth= require './Auth/' | ||
|
||
app.get '/', Index.index | ||
|
||
app.namespace '/user', -> | ||
app.get '/register', User.register | ||
app.get '/change/:id', User.change | ||
app.get '/delete/:id', User.delete | ||
|
||
app.get '/login', Auth.login app.get('passport') | ||
app.get '/callback', Auth.callback app.get('passport'),(req, res) -> res.send 'WOOW' | ||
|
||
|
||
|
||
app.namespace '/car', -> | ||
app.get '/', Car.all | ||
app.get '/add', Car.add | ||
app.get '/:id', Car.one | ||
app.get '/change/:id', Car.change | ||
app.get '/delete/:id', Car.delete | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
ns= require 'express-namespace' | ||
http= require 'http' | ||
fs= require 'fs' | ||
App= module.exports= require 'express' | ||
app= App() | ||
passport = require('./api/Auth/').config() | ||
|
||
|
||
|
||
require('./modules/log/')() | ||
app.use (req,res,next) -> | ||
logger.info req.ip + ' - - ' + req.method + ' ' + req.url + ' - - "' + req.headers.referer + '" "' + req.headers['user-agent'] + '"' | ||
next() | ||
|
||
require('./modules/pid/')(process.env.npm_package_config_pid) | ||
|
||
|
||
|
||
|
||
# | ||
# Конфигурация для работы в штатном режиме | ||
# | ||
app.configure -> | ||
app.use App.compress() | ||
|
||
# статические файлы | ||
app.use App.static __dirname+'/views/assets' | ||
|
||
|
||
# шаблоны вида | ||
app.set 'views', __dirname + '/views/pages' | ||
app.set 'view engine', 'jade' | ||
app.set 'view options', | ||
layout:false | ||
|
||
# обработка входящих данных | ||
app.use App.bodyParser() | ||
app.use App.cookieParser() | ||
app.use App.methodOverride() | ||
|
||
app.use App.session | ||
secret: process.env.npm_package_config_auth_session_secret | ||
|
||
app.locals.title= 'API-server' | ||
|
||
# passport | ||
app.use passport.initialize() | ||
app.use passport.session() | ||
app.set 'passport', passport | ||
|
||
|
||
|
||
# | ||
# Конфигурация для разработки и тестирования | ||
# | ||
app.configure 'development', -> | ||
|
||
app.use App.logger 'tiny' | ||
|
||
app.use App.errorHandler | ||
dumpExceptions: true | ||
showStack : true | ||
|
||
|
||
# | ||
# Сервер приложения | ||
# | ||
port= process.env.npm_package_config_port | ||
|
||
server = http.createServer(app) | ||
server.listen port, -> | ||
logger.info 'Listening on '+port | ||
|
||
|
||
|
||
|
||
# Эйпиай | ||
api= require './api' | ||
api app | ||
|
Oops, something went wrong.