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
// Setup | |
var http = require('http'); // require http module | |
var port = 80; // http port | |
var host = '127.0.0.1' // localhost | |
// This function will be called when a request arrives from a client | |
function onRequest(request, response) { | |
response.writeHead(200, {'Content-Type': 'text/plain'}); // headers | |
response.end('Hello World'); // end response | |
} |
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
app.get('/query', function(request, response){ | |
// Query your database | |
db.query('SELECT * FROM users', function(rows){ | |
// Push notification to dan | |
socket.emit('database_query_executed', 'to_dan', rows); | |
// End request | |
response.end('success'); | |
}); |
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
// this is javascript | |
ajax('http://node.yoursite.com/push', node_options) | |
ajax('http://php.yoursite.com/mysql_query', php_options) |
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
// Call Diet | |
var Application = require('diet'); | |
// Initalize Application | |
app = new Application.setup({ | |
'domain' : 'example.com', // default is localhost (127.0.0.1) | |
'port' : 80, // default is 80 | |
'path' : __dirname, // required path to this folder __dirname is ok | |
'public' : __dirname +'/resources', // required path to the app resources (images etc..) | |
'header' : init, // function that runs when the server loaded completly (mysql etc...) |
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
<!doctype html> | |
<html> | |
<head> | |
<title>{{-@title}}</title> | |
</head> | |
<body> | |
<h1>Hello World in {{-@title}}</h1> | |
</body> | |
</html> |
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
// Listen on http://example.com/ and respond with index.html | |
app.get('/', function(request, response, mysql){ | |
response.html('/index.html', { title: 'Diet.js Example!' }); | |
mysql.end(); | |
}); |
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
subdomain = app.subdomain(app, { | |
domain : 'subdomain.example.com', | |
path : __dirname, | |
public : __dirname+'/resources', | |
mysql : { | |
host : 'YOUR_HOST', // usually localhost | |
user : 'YOUR_USERNAME', // usually root | |
password : 'YOUR_PASSWORD', // your mysql password | |
database : 'YOUR_DATABASE_NAME', // your mysql database | |
}, |
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
var server = require('diet') | |
var app = new server() | |
app.listen('http://localhost:8000/') | |
app.get('/', function($){ | |
$.end('hello world') | |
}) |
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
// Diet with Socket.io example | |
// Diet Server | |
var server = require('diet') | |
var app = server() | |
app.listen(8000) | |
// Socket.io | |
var io = require('socket.io')(app.server) // <-- use app.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
// Diet Server | |
var server = require('diet') | |
var app = server() | |
app.listen(8000) | |
// Socket.io | |
var io = require('socket.io')(app.server) // <-- use app.server | |
// Listen on websocket connection | |
io.on('connection', function(socket){ |