Socket
Socket
Sign inDemoInstall

electron-protocol-serve

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-protocol-serve - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-2

.npmignore

4

CHANGELOG.md
# Changelog
## 1.2.0
- Set environment variable allowing renderer process to set module search path correctly
## 1.1.0

@@ -4,0 +8,0 @@

41

index.js
const { join } = require('path');
const fs = require('fs');
const createHandler = require('./lib/handler');

@@ -20,4 +20,3 @@ function requiredParam(param, errorMessage) {

* @param {String} options.endpoint endpoint of your protocol, defaults to `dist`
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html`
* @param {String} options.indexPath defaults to cwd + directoryIndexFile
* @param {String} options.indexPath defaults to 'index.html' in cwd
*

@@ -32,3 +31,2 @@ * @return {String} name of your protocol

endpoint = 'dist',
directoryIndexFile = 'index.html',
indexPath = undefined,

@@ -40,32 +38,9 @@ }) {

indexPath = indexPath || join(cwd, directoryIndexFile);
indexPath = indexPath || join(cwd, 'index.html');
const cache = {};
const prefixLength = name.length + 3 + endpoint.length;
const options = { cwd, name, endpoint, indexPath };
const handler = createHandler(options);
app.on('ready', () => {
protocol.registerFileProtocol(name, (request, callback) => {
// the request url should start with ' ${name}://${endpoint}', remove that
const [url/* , hash */] = request.url.substr(prefixLength).split('#');
const urlSegments = url.split('/').filter(segment => segment !== '');
if (urlSegments.length === 0) {
urlSegments.push(directoryIndexFile);
}
const filepath = join(cwd, ...urlSegments);
// redirect empty requests to index.html
if (!cache[url]) {
try {
fs.accessSync(filepath);
cache[url] = filepath;
} catch (err) {
//
}
}
callback({ path: cache[url] || indexPath });
}, error => {
protocol.registerFileProtocol(name, handler, error => {
if (error) {

@@ -77,3 +52,7 @@ console.error('Failed to register protocol');

// Set our ELECTRON_PROTOCOL_SERVE_INDEX environment variable so the renderer
// process can find index.html to set it up as its main module path
handler({ url: `${name}://${endpoint}` }, ({ path }) => process.env.ELECTRON_PROTOCOL_SERVE_INDEX = path);
return name;
};
{
"name": "electron-protocol-serve",
"version": "1.1.0",
"version": "1.2.0-2",
"description": "A file protocol that serves any existing file in a directory and redirects everything not found to index.html.",

@@ -10,8 +10,17 @@ "main": "index.js",

"scripts": {
"test": "npm run mocha && npm run lint",
"mocha": "mocha ./tests/**/*-test.js",
"lint": "eslint ."
},
"devDependencies": {
"eslint": "^3.17.1"
"bluebird": "^3.5.0",
"chai": "^3.5.0",
"eslint": "^3.17.1",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"sinon": "^1.17.7"
},
"dependencies": {}
"dependencies": {
"mock-require": "^2.0.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc