Authored by xuqi

init pro

node_modules/
dist/
npm-debug.log
css/*
\ No newline at end of file
... ...
/**
* yohobuy app
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars'),
bodyParser = require('body-parser'),
favicon = require('serve-favicon'),
cookieParser = require('cookie-parser');
var app = express();
// set view engin
app.set('views', path.join(__dirname, 'app/views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: 'app/views/',
partialsDir: 'app/views/partial/',
helpers: 'helpers'
}));
app.set('view engine', '.hbs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// router
app.use('/', require('./router'));
// listener
app.listen(3000, function() {
console.log('yohobuy start');
});
\ No newline at end of file
... ...
hello hbs
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{title}}</title>
<meta name="keywords" content="{{keywords}}">
<meta name="description" content="{{description}}">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<link rel="dns-prefetch" href="//cdn.yoho.cn">
<link rel="dns-prefetch" href="//static.yohobuy.com">
<link rel="dns-prefetch" href="//img12.static.yhbimg.com">
<link rel="dns-prefetch" href="//img13.static.yhbimg.com">
</head>
<body>
{{> header}}
{{{body}}}
</body>
</html>
\ No newline at end of file
... ...
<p>I am header</p>
\ No newline at end of file
... ...
/**
* 接口公共方法
* @author: xuqiMqi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const rp = require('request-promise');
const _ = require('lodash');
class API {
/**
* get
* @param url String
* @param data Obejct
*/
get(url, data) {
return rp({
url: `${this.server}${url}`,
qs: data
});
}
/**
* multi get
* @params: urls => Array[Object[url[string], data[object]]]
*/
multiGet(urls) {
var rps = [],
self = this;
_.forEach(urls, function(el) {
rps.push(rp({
url: `${self.server}${el.url}`,
qs: el.data
}));
});
return Promise.all(rps).then((d) => {
return d;
});
}
/**
* post
* @param url String
* @param data Obejct
*/
post(url, data) {
return rp({
url: `${this.server}${url}`,
method: 'post',
form: data
});
}
}
module.exports = API;
\ No newline at end of file
... ...
/**
* 登录判断
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
module.exports = (req, res, next) => {
next();
};
\ No newline at end of file
... ...
{
"name": "yohobuy-node",
"version": "0.0.1",
"description": "A New Yohobuy Project With Express",
"repository": {
"type": "git",
"url": "http://git.dev.yoho.cn/web/yohobuy-node.git"
},
"license": "MIT",
"dependencies": {
"express": "^4.13.1",
"body-parser": "^1.15.0",
"cookie-parser": "^1.4.1",
"express-handlebars": "^3.0.0",
"lodash": "^4.8.2",
"morgan": "^1.7.0",
"request-promise": "^2.0.1",
"serve-favicon": "^2.3.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"autoprefixer": "^6.3.6",
"gulp-cssnano": "^2.1.2",
"gulp-postcss": "^6.1.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.2",
"postcss-calc": "^5.2.1",
"postcss-center": "^1.0.0",
"postcss-clearfix": "^1.0.0",
"postcss-crip": "^2.0.0",
"postcss-opacity": "^3.0.0",
"postcss-position": "^0.4.0",
"postcss-short": "^1.4.0",
"postcss-sprites": "^3.1.2",
"postcss-use": "^2.0.2",
"precss": "^1.4.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-stream": "^3.1.0"
}
}
\ No newline at end of file
... ...
/**
* router
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const app = new require('express').Router();
const cRoot = './app/controllers';
app.get('/', (req, res) => {
res.render('index');
});
module.exports = app;
\ No newline at end of file
... ...