Last active
August 29, 2015 13:57
-
-
Save yitsushi/9508012 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
node_modules | |
npm-debug.log |
This file contains hidden or 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
// Betöltjük az express-t, http-t és a path-t | |
var express = require('express'), | |
http = require('http'), | |
path = require('path'); | |
// Betöltjük a routokat. | |
// Kvázi kontrollereket vagy nevezd, | |
// aminek akarod | |
var routes = require('./routes'); | |
// Inicializáljuk az express alkalmazást | |
var app = express(); | |
// Ide jönnek az express alkalmazás beállításai | |
app.configure(function() { | |
// használjuk portnak a PORT környezeti változót, | |
// ha nincs, akkor a 3000-es portot | |
app.set('port', process.env.PORT || 3000); | |
// A view-k helyét megadjuk | |
app.set('views', __dirname + '/views'); | |
// A view-knál használt template motorként a jade-et | |
// szeretnénk használni | |
app.set('view engine', 'jade'); | |
// Használja az express favicon-ját, ha nincs más | |
app.use(express.favicon()); | |
// Gzip tömörítés mindig jól jön | |
app.use(express.compress()); | |
// A rendszer végezzen minden kérésnél elemzést és | |
// bontsa fel nekünk a kérések body részét, ami a POST | |
// kéréseknél hasznos | |
app.use(express.bodyParser()); | |
// Ha szeretnénk használni (márpedig szeretnénk) | |
// a PUT és DELETE megnevezésű HTTP metódusokat | |
// akkor ez elengethetetlen | |
app.use(express.methodOverride()); | |
// A cookie-k használatát is engedélyezzük | |
// és állítsunk be hozzá valami véletlenszerűen generált | |
// salt-ot | |
app.use(express.cookieParser('pramboshnypDicOmLertevNocgocUn')); | |
// A stíluslapokhoz stylus-t használunk, amit a public | |
// könyvtárban használunk | |
app.use(require('stylus').middleware(__dirname + '/public')); | |
// A statikus részek, mint javascript-ek, css-ek, képek | |
// mind a public könyvtárban lesznek | |
app.use(express.static(path.join(__dirname, 'public'))); | |
// alkalmazzuk a routokat (lentebbről) | |
app.use(app.router); | |
}); | |
// Ha a NODE_ENV környezeti változó nincs definiálva, akkor | |
// alapértelmezetten development env-ként értelmezi | |
// itt be tudjuk állítani, hogy mi legyen akkor, | |
// ha dev módban vagyunk | |
app.configure('development', function(){ | |
// jelen esetben logoljunk minden kérést, | |
// hogy milyen metódussal, milyen URL-t kértek, | |
// mennyi ideig tartott és milyen status-t kapott | |
app.use(express.logger({ format: ':method :url :response-time ms [:status]' })); | |
// hiba esetén mindent kérünk | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
}); | |
// Production módban nem akatunk minden kérést console.log-olni. | |
app.configure('production', function() { | |
app.use(express.errorHandler()); | |
}); | |
// Most akkor állítsuk be a routokat | |
// Ezt most nem definiáljuk, mert | |
// jelen esetben szeretnénk, ha az index.html lenne használva | |
// a public-ból, amikor betöltjük az oldalt. | |
//app.get("/", routes.index); | |
// Ha egyik fentebbi route sem volt jó, akkor | |
// dobjunk egy 404-es oldalt | |
app.use(function(req, res, next){ | |
res.status(404); | |
res.render( | |
'error/404', | |
{ | |
method: req.method, | |
path: req.path | |
} | |
); | |
}); | |
// Indítsuk el úgy, hogy csinálunk egy új HTTP szervert, aminek megadjuk | |
// paraméterben az express alkalmazásunkat, majd beállítjuk, hogy | |
// az express-nek megadott porton figyeljen, ha pedig elindult, akkor | |
// irjuk ki a console-ra eme csodás pillanatot, milyen portot kapott | |
// és milyen NODE_ENV-ben fut | |
var httpServer = http.createServer(app).listen(app.get('port'), function(){ | |
console.log("Express server listening on port " | |
+ app.get('port') | |
+ " (" + app.settings.env + ")"); | |
}); |
This file contains hidden or 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
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'}); | |
var now = new Date(); | |
// Friday | |
if (now.getDay() == 5) { | |
return res.end("Igen! Ma péntek van."); | |
} | |
// Weekend | |
if (now.getDay() == 0 || now.getDay() == 6) { | |
return res.end("Mit számít? Hiszen hétvége van."); | |
} | |
// Sad days | |
return res.end("Nem, nincs péntek. De nyugi már csak " | |
+ (5 - now.getDay()) | |
+ " napot kell túlélni.") | |
}).listen(3000); |
This file contains hidden or 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
{ | |
"name": "foly-am", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "node app" | |
}, | |
"dependencies": { | |
"express": "3.0.0rc2", | |
"jade": "*", | |
"stylus": "*", | |
"mongoose": "3.5.4" | |
}, | |
"engines":{ | |
"node": "0.10.x", | |
"npm": "1.2.x" | |
} | |
} |
This file contains hidden or 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
web: node app.js |
This file contains hidden or 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
<html ng-app> | |
<head> | |
<link rel="stylesheet" href="/stylesheets/main.css"> | |
<script type="text/javascript" src="/javascripts/angular.min.js"></script> | |
<script type="text/javascript" src="/javascripts/app.js"></script> | |
</head> | |
<body> | |
<div ng-controller='App.controllers.Link'> | |
<form ng-submit="addLink()"> | |
<input type="text" | |
ng-model="newLink" | |
placeholder="add new link here"> | |
<input type="submit" value="add"> | |
</form> | |
<table> | |
<tr> | |
<th>Short link</th> | |
<th>Target link</th> | |
<th>Clicks</th> | |
<th>Created at</th> | |
</tr> | |
<tr ng-repeat="link in links"> | |
<td><a href="{{link.short}}">{{link.short}}</a></td> | |
<td><a href="{{link.long}}">{{link.long}}</a></td> | |
<td>{{link.clicks}}</td> | |
<td>{{link.created_at}}</td> | |
</tr> | |
</table> | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
module.exports.index = function(req, res) { | |
res.json({ "wtf": true }); | |
}; |
This file contains hidden or 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
!!!5 | |
html | |
head | |
title Not found @ Foly.am | |
body | |
h1 A keresett oldal nem található |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment