Skip to content

Commit f10b8fd

Browse files
Christian PippertChristian Pippert
Christian Pippert
authored and
Christian Pippert
committed
first commit
0 parents  commit f10b8fd

17 files changed

+308
-0
lines changed

.bowerrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"directory": "public/components",
3+
"json": "bower.json"
4+
}

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
public/components
3+
.sass-cache

Gruntfile.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict';
2+
3+
var request = require('request');
4+
5+
module.exports = function (grunt) {
6+
// show elapsed time at the end
7+
require('time-grunt')(grunt);
8+
// load all grunt tasks
9+
require('load-grunt-tasks')(grunt);
10+
11+
var reloadPort = 35729, files;
12+
13+
grunt.initConfig({
14+
pkg: grunt.file.readJSON('package.json'),
15+
develop: {
16+
server: {
17+
file: 'app.js'
18+
}
19+
},
20+
less: {
21+
dist: {
22+
files: {
23+
'public/css/style.css': 'public/css/style.less'
24+
}
25+
}
26+
},
27+
watch: {
28+
options: {
29+
nospawn: true,
30+
livereload: reloadPort
31+
},
32+
js: {
33+
files: [
34+
'app.js',
35+
'app/**/*.js',
36+
'config/*.js'
37+
],
38+
tasks: ['develop', 'delayed-livereload']
39+
},
40+
css: {
41+
files: [
42+
'public/css/*.less'
43+
],
44+
tasks: ['less'],
45+
options: {
46+
livereload: reloadPort
47+
}
48+
},
49+
views: {
50+
files: [
51+
'app/views/*.jade',
52+
'app/views/**/*.jade'
53+
],
54+
options: { livereload: reloadPort }
55+
}
56+
}
57+
});
58+
59+
grunt.config.requires('watch.js.files');
60+
files = grunt.config('watch.js.files');
61+
files = grunt.file.expand(files);
62+
63+
grunt.registerTask('delayed-livereload', 'Live reload after the node server has restarted.', function () {
64+
var done = this.async();
65+
setTimeout(function () {
66+
request.get('http://localhost:' + reloadPort + '/changed?files=' + files.join(','), function(err, res) {
67+
var reloaded = !err && res.statusCode === 200;
68+
if (reloaded)
69+
grunt.log.ok('Delayed live reload successful.');
70+
else
71+
grunt.log.error('Unable to make a delayed live reload.');
72+
done(reloaded);
73+
});
74+
}, 500);
75+
});
76+
77+
grunt.registerTask('default', [
78+
'less',
79+
'develop',
80+
'watch'
81+
]);
82+
};

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"# sensors"

app.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
var express = require('express'),
4+
config = require('./config/config');
5+
6+
var app = express();
7+
8+
require('./config/express')(app, config);
9+
10+
app.listen(config.port, function () {
11+
console.log('Express server listening on port ' + config.port);
12+
});
13+

app/controllers/home.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var express = require('express'),
2+
router = express.Router(),
3+
Article = require('../models/article');
4+
5+
module.exports = function (app) {
6+
app.use('/', router);
7+
};
8+
9+
router.get('/', function (req, res, next) {
10+
res.json({});
11+
/**
12+
res.render('index', {
13+
title: 'Generator-Express MVC',
14+
articles: articles
15+
});
16+
**/
17+
});
18+
19+
router.get('/getCurrentTemperatur', function (req, res, next) {
20+
res.json({string: 'hallo rest'});
21+
});
22+
23+
router.get('/getLedStatus', function (req, res, next) {
24+
res.json({string: 'hallo LED Status'});
25+
});

app/models/article.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Example model
2+
3+
4+
function Article (opts) {
5+
if(!opts) opts = {};
6+
this.title = opts.title || '';
7+
this.url = opts.url || '';
8+
this.text = opts.text || '';
9+
}
10+
11+
module.exports = Article;
12+

app/views/error.jade

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends layout
2+
3+
block content
4+
h1= message
5+
h2= error.status
6+
pre #{error.stack}

app/views/index.jade

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends layout
2+
3+
block content
4+
h1= title
5+
p Welcome to my App #{title}
6+
p= articles

app/views/layout.jade

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
doctype html
2+
html(lang='en')
3+
head
4+
meta(charset='UTF-8')
5+
meta(name='viewport', content='width=device-width')
6+
title= title
7+
block css
8+
link(rel='stylesheet', href='/css/style.css')
9+
block js
10+
if ENV_DEVELOPMENT
11+
script(src='http://localhost:35729/livereload.js')
12+
body
13+
block content

bower.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "myproject",
3+
"version": "0.0.1",
4+
"ignore": [
5+
"**/.*",
6+
"node_modules",
7+
"components"
8+
]
9+
}

config/config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var path = require('path'),
2+
rootPath = path.normalize(__dirname + '/..'),
3+
env = process.env.NODE_ENV || 'development';
4+
5+
var config = {
6+
development: {
7+
root: rootPath,
8+
app: {
9+
name: 'myproject'
10+
},
11+
port: 3000,
12+
},
13+
14+
test: {
15+
root: rootPath,
16+
app: {
17+
name: 'myproject'
18+
},
19+
port: 3000,
20+
},
21+
22+
production: {
23+
root: rootPath,
24+
app: {
25+
name: 'myproject'
26+
},
27+
port: 3000,
28+
}
29+
};
30+
31+
module.exports = config[env];

config/express.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var express = require('express');
2+
var glob = require('glob');
3+
4+
var favicon = require('serve-favicon');
5+
var logger = require('morgan');
6+
var cookieParser = require('cookie-parser');
7+
var bodyParser = require('body-parser');
8+
var compress = require('compression');
9+
var methodOverride = require('method-override');
10+
11+
module.exports = function(app, config) {
12+
var env = process.env.NODE_ENV || 'development';
13+
app.locals.ENV = env;
14+
app.locals.ENV_DEVELOPMENT = env == 'development';
15+
16+
//app.set('views', config.root + '/app/views');
17+
//app.set('view engine', 'jade');
18+
19+
// app.use(favicon(config.root + '/public/img/favicon.ico'));
20+
app.use(logger('dev'));
21+
app.use(bodyParser.json());
22+
app.use(bodyParser.urlencoded({
23+
extended: true
24+
}));
25+
app.use(cookieParser());
26+
app.use(compress());
27+
app.use(express.static(config.root + '/public'));
28+
app.use(methodOverride());
29+
30+
var controllers = glob.sync(config.root + '/app/controllers/*.js');
31+
controllers.forEach(function (controller) {
32+
require(controller)(app);
33+
});
34+
35+
app.use(function (req, res, next) {
36+
var err = new Error('Not Found');
37+
err.status = 404;
38+
next(err);
39+
});
40+
41+
42+
app.use(function (err, req, res, next) {
43+
res.status(err.status || 500);
44+
res.json({
45+
status: err.status,
46+
message: err.message,
47+
});
48+
});
49+
50+
};

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "myproject",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"start": "node app.js"
7+
},
8+
"dependencies": {
9+
"express": "^4.13.3",
10+
"serve-favicon": "^2.3.0",
11+
"morgan": "^1.6.1",
12+
"cookie-parser": "^1.3.3",
13+
"body-parser": "^1.13.3",
14+
"compression": "^1.5.2",
15+
"method-override": "^2.3.0",
16+
"glob": "^6.0.4",
17+
"jade": "^1.11.0"
18+
},
19+
"devDependencies": {
20+
"grunt": "^0.4.5",
21+
"grunt-develop": "^0.4.0",
22+
"grunt-contrib-less": "^1.0.0",
23+
"grunt-contrib-watch": "^0.6.1",
24+
"request": "^2.60.0",
25+
"time-grunt": "^1.2.1",
26+
"load-grunt-tasks": "^3.2.0"
27+
}
28+
}

public/css/style.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
padding: 50px;
3+
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4+
}
5+
a {
6+
color: #00B7FF;
7+
}

public/css/style.less

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body {
2+
padding: 50px;
3+
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4+
}
5+
6+
a {
7+
color: #00B7FF;
8+
}

0 commit comments

Comments
 (0)