-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use stream protocol, update titlebar insert point
- Loading branch information
Paul Varache
committed
Mar 6, 2018
1 parent
9af8d96
commit 0ac76ab
Showing
8 changed files
with
3,977 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
Thumbs.db |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
<link rel="stylesheet" href="./main.css"> | ||
</head> | ||
<body> | ||
|
||
<h1>Content</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const { protocol } = require('electron'); | ||
const spaHandler = require('./spa-file-protocol-handler'); | ||
const spaHandler = require('./spa-stream-protocol-handler'); | ||
|
||
function registerProtocol(scheme, root, handler = () => {}) { | ||
protocol.registerFileProtocol(scheme, spaHandler(root), handler); | ||
protocol.registerStreamProtocol(scheme, spaHandler(root), handler); | ||
} | ||
|
||
module.exports = { registerProtocol }; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const url = require('url'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const mime = require('mime-types'); | ||
|
||
function getExtension(p) { | ||
const parts = p.split('/'); | ||
const lastPart = parts[parts.length - 1]; | ||
return lastPart.split('.').pop(); | ||
} | ||
|
||
module.exports = function getHandler(root, fallback = 'index.html') { | ||
return (req, callback) => { | ||
// Parse the url to extract the pathname | ||
const u = url.parse(req.url); | ||
let extension = getExtension(u.pathname); | ||
// If the path contains an extension, it is a request for a file | ||
const isFile = extension !== ''; | ||
// Replace the path with the fallback file if the request is not for a file | ||
const filename = isFile ? u.pathname : fallback; | ||
extension = getExtension(filename); | ||
const file = path.normalize(`${root}/${filename}`); | ||
const mimeType = mime.lookup(extension); | ||
const stream = fs.createReadStream(file); | ||
callback({ statusCode: 200, headers: { 'content-type': mimeType }, data: stream }); | ||
}; | ||
}; |
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
Oops, something went wrong.