Skip to content

Commit

Permalink
fix(hosting): fixes some issues with self-hosting when dependencies a…
Browse files Browse the repository at this point in the history
…re hoisted
  • Loading branch information
wessberg committed Mar 5, 2019
1 parent 471ef6e commit d4958fd
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ These two services are very much alike. In fact, `Polyfiller` depends on the lib

`Polyfiller` is already hosted at `https://polyfill.app/api` as a **free** web service, but feel free to host it yourself.
The server is built with support for both HTTP2 and HTTP. The environment variable `HTTP2=[true|false]` decides whether a HTTP2 server will be hosted or not.
If you use a load balancer and something like `nginx` in a reverse proxy setup, please know that `nginx` doesn't support HTTP2 via its proxy module, so you have to use HTTP1.1 there. Thankfully, it is as easy as setting `HTTP2=false` before launching the server
If you use a load balancer and something like `nginx` in a reverse proxy setup, please know that `nginx` doesn't support HTTP2 via its proxy module, so you have to use HTTP1.1 there. Thankfully, it is as easy as setting `HTTP2=false` before launching the server and setting `HTTPS=false`.

## Logo

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.63",
"description": "Never worry about polyfills again.",
"files": [
"dist/**/*.*"
"dist/**/*.*",
"src/**/*.*"
],
"scripts": {
"serve": "node ./dist/index.js",
Expand Down Expand Up @@ -88,6 +89,7 @@
"devcert": "^1.0.0",
"events-polyfill": "^2.1.0",
"file-type": "^10.8.0",
"find-up": "^3.0.0",
"http-status-codes": "^1.3.0",
"iltorb": "^2.4.1",
"intersection-observer": "^0.5.1",
Expand Down
1 change: 1 addition & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const config: IConfig = {
verbose: booleanize(environment.VERBOSE),
clearCache: booleanize(environment.CLEAR_CACHE),
http2: booleanize(environment.HTTP2),
https: booleanize(environment.HTTPS),
host: environment.HOST,
port: parseInt(environment.PORT),
email: environment.EMAIL != null && environment.EMAIL !== "" ? environment.EMAIL : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/config/i-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export declare type IConfig = typeof environment & {
verbose: boolean;
clearCache: boolean;
http2: boolean;
https: boolean;
port: number;
host: string;
email: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/environment/environment-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const environmentDefaults = {
DEBUG: "false",
VERBOSE: "false",
HTTP2: "true",
HTTPS: "true",
CLEAR_CACHE: "false",
HOST: "0.0.0.0",
PORT: "3000",
Expand Down
5 changes: 3 additions & 2 deletions src/service/polyfill-builder/polyfill-builder-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ILoggerService} from "../logger/i-logger-service";
import {ensureArray} from "../../util/ensure-array/ensure-array";
import {IFlattenerService} from "../flattener/i-flattener-service";
import {PolyfillDealiasedName} from "../../polyfill/polyfill-name";
import {sync} from "find-up";

/**
* A service that can load and cache all polyfills
Expand Down Expand Up @@ -82,8 +83,8 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {

const flatten = match.flatten === true;

const rootDirectory =
"library" in match ? join(__dirname, "../node_modules", typeof match.library === "string" ? match.library : match.library[polyfillFeature.context]) : join(__dirname, "../");
const rootDirectory = "library" in match ? sync(join("node_modules", typeof match.library === "string" ? match.library : match.library[polyfillFeature.context]))! : join(sync("src")!, "../");

const localPaths =
"library" in match
? Array.isArray(match.relativePaths)
Expand Down
4 changes: 2 additions & 2 deletions src/util/cert/cert-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {certificateFor} from "devcert";
* @param {IGetCertificateOptions} options
* @returns {Promise<{key: Buffer|undefined, cert: Buffer|undefined}>}
*/
export async function getCertificates({key, cert, production, host}: IGetCertificateOptions): Promise<{key: Buffer | undefined; cert: Buffer | undefined}> {
export async function getCertificates({key, cert, production, host, https}: IGetCertificateOptions): Promise<{key: Buffer | undefined; cert: Buffer | undefined}> {
// If a key and certificate was already given, use those two
if (key != null && cert != null) return {key, cert};

// Otherwise, if not in production, use devcert to generate a new certificate
if (!production) {
if (!production && https) {
return await certificateFor(host);
}

Expand Down
1 change: 1 addition & 0 deletions src/util/cert/i-get-certificate-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface IGetCertificateOptions {
cert?: Buffer;
host: string;
production: boolean;
https: boolean;
}
12 changes: 12 additions & 0 deletions src/util/path-util/path-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {sync} from "find-up";

/**
* Finds the
* @param {string} cwd
* @param {string} moduleName
* @return {string | undefined}
*/
export function findModuleRoot(cwd: string, moduleName: string): string | undefined {
const result = sync(`node_modules/${moduleName}`, {cwd});
return result == null ? undefined : result;
}

0 comments on commit d4958fd

Please sign in to comment.