Last active
December 26, 2015 21:09
-
-
Save guybedford/7214487 to your computer and use it in GitHub Desktop.
SPDY asset server API
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 spdy = require('spdy'); // node-spdy | |
var spdyAssetServer = require('spdy-asset-server'); // the proposed spdy-asset-server library | |
// given a url, provide the asset response stream | |
// custom serving function allows dynamic + static assets | |
var assetServer = new spdyAssetServer(function(url, stream) { | |
if (url == 'style/style.css') | |
stream.pipe(fs.createReadStream('/local/file/system/style.css')); | |
else if (url == 'style/style.less') | |
stream.pipe(less.createEncodingStream(fs.createReadStream('/local/file/system/style.less'))); | |
}); | |
var server = spdy.createServer(function(req, res) { | |
if (req.url.substr(0, 6) == 'style/') | |
assetServer.serve(req); | |
else | |
// normal server serving here | |
}); | |
server.listen(443); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that SPDY push for JavaScript modules with import syntax ONLY applies to imports that are relative names:
import "./relative" / import "../some/module"
. Standard relative resolution rules for all loaders MUST thus be an assumption of the module system.