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
require('marko/node-require').install(); | |
var EventEmitter = require('events').EventEmitter; | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
/** | |
* This function serves like an SSE end point which pushes data. | |
* Data is emitted in chunks here. | |
*/ |
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
require('marko/node-require').install(); | |
var EventEmitter = require('events').EventEmitter; | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
/** | |
* This function serves like an SSE end point which pushes data. | |
* Data is emitted in chunks here. | |
*/ |
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
require('marko/node-require').install(); | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
const indexTemplate = require('./index.marko'); | |
server.on('request', (req, res) => { | |
var out = require('async-writer').create(res); | |
out.write('<h1>------Before body--------</h1>'); | |
indexTemplate.render({ |
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
require('marko/node-require').install(); | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
server.on('request', (req, res) => { | |
var out = require('async-writer').create(res); | |
out.write('A'); | |
var asyncOut = out.beginAsync(); | |
setTimeout(function() { |
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
require('marko/node-require').install(); | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
server.on('request', (req, res) => { | |
var out = require('async-writer').create(res) | |
.on('error', function(err) { | |
// Something went wrong during writing | |
}) |
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
require('marko/node-require').install(); | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
const indexTemplate = require('./index.marko'); | |
server.on('request', (req, res) => { | |
res.write('<h1>------Before body--------</h1>'); | |
indexTemplate.render({ | |
name: 'Frank', | |
count: 30, |
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
<html> | |
<head></head> | |
<body> | |
<p>Hello ${data.name}! You have ${data.count} messages!</p> | |
<ul if(data.colors && data.colors.length)> | |
<li style="color: ${color}" for(color in data.colors)>${color}</li> | |
</ul> | |
<include("./footer.marko") name=data.name/> | |
</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
{ | |
"name": "marko3-http", | |
"version": "0.0.0", | |
"description": "Example of using Marko with a simple Node.js HTTP server", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ | |
"marko", |
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
require('marko/node-require').install(); | |
const http = require('http'); | |
const server = require('http').createServer(); | |
const port = 8080; | |
const indexTemplate = require('./index.marko'); | |
server.on('request', (req, res) => { | |
indexTemplate.render({ | |
name: 'Frank', | |
count: 30, | |
colors: ['red', 'green', 'blue'] |
NewerOlder