Skip to content
Permalink
Browse files

A proof-of-concept for browser-side includes.

  • Loading branch information...
kickscondor committed Aug 28, 2018
1 parent 4611580 commit 9ccadcc866326878bd4b463904598d1b3c3b8869
Showing with 15 additions and 0 deletions.
  1. +13 −0 dat/protocol.js
  2. +2 −0 package.json
@@ -2,10 +2,12 @@ const {join} = require('path')
const parseDatUrl = require('parse-dat-url')
const parseRange = require('range-parser')
const once = require('once')
const deasync = require('deasync')
const debug = require('../lib/debug-logger').debugLogger('dat-serve')
const pda = require('pauls-dat-api')
const intoStream = require('into-stream')
const toZipStream = require('hyperdrive-to-zip-stream')
const replace = require('replacestream');
const slugify = require('slugify')

const datDns = require('./dns')
@@ -320,6 +322,17 @@ exports.electronHandler = async function (request, respond) {
dataStream.destroy() // stop reading data
respond({statusCode: 204, headers, data: intoStream('')})
} else {
if (mimeType.startsWith("text/html")) {
dataStream = dataStream.pipe(replace(
/<!-- *#include +file="([^"]+)" *-->/g,
(match, incpath) => {
var datread = deasync(pda.readFile)
if (manifest && manifest.web_root) {
incpath = join(manifest.web_root, incpath)
}
return datread(archive, incpath)
}))
}
respond({statusCode, headers, data: dataStream})
}
}))
@@ -38,6 +38,7 @@
"dat-dns": "^3.0.2",
"dat-encoding": "^5.0.1",
"datland-swarm-defaults": "^1.0.2",
"deasync": "^0.1.13",
"diff": "^3.5.0",
"diff-file-tree": "^2.1.2",
"discovery-swarm": "^5.1.2",
@@ -69,6 +70,7 @@
"sodium-signatures": "^2.1.1",
"split2": "^2.2.0",
"sqlite3": "^4.0.1",
"replacestream": "^4.0.3",
"stream-throttle": "^0.1.3",
"textextensions": "^2.2.0",
"through2": "^2.0.3",

0 comments on commit 9ccadcc

Please sign in to comment.
You can’t perform that action at this time.