Skip to content

Commit

Permalink
Merge pull request #184 from drashland/issue-#183-support-https
Browse files Browse the repository at this point in the history
[issue-#183-support-https] support https
  • Loading branch information
ebebbington committed Apr 18, 2020
2 parents 1a36dac + 85c3979 commit 1196f92
Show file tree
Hide file tree
Showing 23 changed files with 327 additions and 215 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -34,12 +34,14 @@ class HomeResource extends Drash.Http.Resource {
}

const server = new Drash.Http.Server({
address: "localhost:1337",
response_output: "text/html",
resources: [HomeResource]
});

server.run();
server.run({
hostname: "localhost",
port: 1447
});
```

```
Expand Down
5 changes: 4 additions & 1 deletion deps.ts
@@ -1,6 +1,9 @@
export {
HTTPOptions,
HTTPSOptions,
ServerRequest,
serve
serve,
serveTLS,
} from "https://deno.land/std@v0.41.0/http/server.ts";

export {
Expand Down
6 changes: 5 additions & 1 deletion example_app/app.ts
@@ -1,3 +1,7 @@
import { Drash } from "../mod.ts";
import server from "./app_server.ts";
server.run();

server.run({
hostname: "localhost",
port: 1667
});
10 changes: 10 additions & 0 deletions example_app/app_https.ts
@@ -0,0 +1,10 @@
import { Drash } from "../mod.ts";
import server from "./app_server.ts";

server.runTLS({
hostname: "localhost",
port: 1447,
certFile: "./tls/server.crt",
keyFile: "./tls/server.key"
});

1 change: 0 additions & 1 deletion example_app/app_server.ts
Expand Up @@ -16,7 +16,6 @@ import ViewResource from "./view_resource.ts";
import Middleware from "./middleware.ts";

let server = new Drash.Http.Server({
address: "localhost:1447",
directory: Deno.realpathSync("./"),
response_output: "application/json",
logger: new Drash.CoreLoggers.ConsoleLogger({
Expand Down
1 change: 0 additions & 1 deletion example_app/app_server_two.ts
Expand Up @@ -7,7 +7,6 @@ import { Drash } from "../mod.ts";
import ViewResource from "./view_resource.ts";

const serverTwo = new Drash.Http.Server({
address: "localhost:1447",
directory: Deno.realpathSync("./"),
resources: [
ViewResource,
Expand Down
5 changes: 4 additions & 1 deletion example_app/app_test.ts
@@ -1,6 +1,9 @@
import members from "../tests/members.ts";
import server from "./app_server.ts";
server.run({ address: "localhost:1667" });
server.run({
hostname: "localhost",
port: 1667
});

import "./coffee_resource_test.ts";
import "./cookie_resource_test.ts";
Expand Down
5 changes: 4 additions & 1 deletion example_app/app_two_test.ts
Expand Up @@ -5,7 +5,10 @@

import members from "../tests/members.ts";
import serverTwo from "./app_server_two.ts";
serverTwo.run({ address: "localhost:1667" });
serverTwo.run({
hostname: "localhost",
port: 1667
});

members.test("ViewResource - Template Engine", async () => {
let response = await members.fetch.get(
Expand Down
20 changes: 20 additions & 0 deletions example_app/tls/server.crt
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDUjCCAjoCCQDgYJ0va8AdODANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJV
UzEXMBUGA1UECAwOTm9ydGggQ2Fyb2xpbmExDTALBgNVBAcMBEFwZXgxDjAMBgNV
BAoMBURyYXNoMSQwIgYJKoZIhvcNAQkBFhVlcmljLmNyb29rc0BnbWFpbC5jb20w
HhcNMjAwNDE4MDUxNTQwWhcNMjEwNDE4MDUxNTQwWjBrMQswCQYDVQQGEwJVUzEX
MBUGA1UECAwOTm9ydGggQ2Fyb2xpbmExDTALBgNVBAcMBEFwZXgxDjAMBgNVBAoM
BURyYXNoMSQwIgYJKoZIhvcNAQkBFhVlcmljLmNyb29rc0BnbWFpbC5jb20wggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCTEX+Y9kPJ0j8x1+CvN2MvR0Mh
Vn5hlfd1oAkvuGLjaPwbHi/skDQ7aiPg/rHLmR7BPStNRsK3695Q37J/RqUFOuJc
ZlH6Mg19ruQfQr85kPSUygtV8jAYguVI8yJdGeWw7zuxICmmzFdaf5akf4jfbnip
7aovQ9UOeffSs3B15DdYT1ijdE/NKHdr16G+SGB9C/nlSIBIE6lduyg1Wgi2wzYm
aGPPEV83wOgzpBgumyLETL78M4FCxdLt30VBkVQYkXc9cmEs3vSO2Oe2dmzfgE8C
4vWrE4NjNoLuNQ+ufyGAkD8YQNkETr8P6SfE9FbrTI2g2+wqG9k82B1+GoiDAgMB
AAEwDQYJKoZIhvcNAQELBQADggEBAGzl2iWNwQBHhgypNVp6vQjyd6LH7XD5VmTh
5XPeb7dWeRh8fMEr0lxJ1JoMwXoHb65AjyypZz39J7rqHp/+agrL96g+5KiFS24l
8qXsIMyAOuYcf0O45Cm1LNeWfkaKoq2sbbCRgNPD09FjWCoDIrXb5BA/i//+Bqi3
Yi/6gB8OyKDcp5JV4PtWlh2yXU/RMed3/cOAinD1HMsHQsR7/PFbKcD3O4sjjOHn
7XLWODZI7NTkeHst0QojVZl/9gCN/BWgsSdTTD+mTmHkPIwr3iQo/1QOhIlGZUIn
T1yGL28DLsqTCDmwcuSarWFPo/kQYd9A/XrU6Z82HfOEpWtd898=
-----END CERTIFICATE-----
17 changes: 17 additions & 0 deletions example_app/tls/server.csr
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICyjCCAbICAQAwazELMAkGA1UEBhMCVVMxFzAVBgNVBAgMDk5vcnRoIENhcm9s
aW5hMQ0wCwYDVQQHDARBcGV4MQ4wDAYDVQQKDAVEcmFzaDEkMCIGCSqGSIb3DQEJ
ARYVZXJpYy5jcm9va3NAZ21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEAkxF/mPZDydI/MdfgrzdjL0dDIVZ+YZX3daAJL7hi42j8Gx4v7JA0
O2oj4P6xy5kewT0rTUbCt+veUN+yf0alBTriXGZR+jINfa7kH0K/OZD0lMoLVfIw
GILlSPMiXRnlsO87sSAppsxXWn+WpH+I3254qe2qL0PVDnn30rNwdeQ3WE9Yo3RP
zSh3a9ehvkhgfQv55UiASBOpXbsoNVoItsM2JmhjzxFfN8DoM6QYLpsixEy+/DOB
QsXS7d9FQZFUGJF3PXJhLN70jtjntnZs34BPAuL1qxODYzaC7jUPrn8hgJA/GEDZ
BE6/D+knxPRW60yNoNvsKhvZPNgdfhqIgwIDAQABoBowGAYJKoZIhvcNAQkHMQsM
CWNoYWxsZW5nZTANBgkqhkiG9w0BAQsFAAOCAQEAJ87DmoHPiXEOKyo0tW2xHHLT
1drqfa5MMDJcV4Hahp1oicJ1BF0m0tLesnl/6QYWvxu+LFUNtXExiQ+gBEngcB9V
9MjEH273DuoMAnJEtc6x8c2EvUI8rN08ipXBX+bYnXzbzS2Fe0UXZuKuGinPVX1M
dJo6Zp5p5kwirBGjpCx2Lqqf/il3TV2VFa5wh4U4eBvFiSD49gk8uy0WA2yrzW2O
q6FGXu7oG2l+af3bYk2VYvxX7hRyEZnXCFuZoG52rNiIXNOAIF8uE+3N9gcYu5Mv
3ttTKNBMXKEjN7cRGT66MKlfJ5qMbuhQO9aPAveUiYCyciPPGYSWOrJVi1GYXw==
-----END CERTIFICATE REQUEST-----
27 changes: 27 additions & 0 deletions example_app/tls/server.key
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAkxF/mPZDydI/MdfgrzdjL0dDIVZ+YZX3daAJL7hi42j8Gx4v
7JA0O2oj4P6xy5kewT0rTUbCt+veUN+yf0alBTriXGZR+jINfa7kH0K/OZD0lMoL
VfIwGILlSPMiXRnlsO87sSAppsxXWn+WpH+I3254qe2qL0PVDnn30rNwdeQ3WE9Y
o3RPzSh3a9ehvkhgfQv55UiASBOpXbsoNVoItsM2JmhjzxFfN8DoM6QYLpsixEy+
/DOBQsXS7d9FQZFUGJF3PXJhLN70jtjntnZs34BPAuL1qxODYzaC7jUPrn8hgJA/
GEDZBE6/D+knxPRW60yNoNvsKhvZPNgdfhqIgwIDAQABAoIBAHh7GFX+QVCALgcu
PEIulNGxhpw0GHrneX9iKMRwQIregdHRbB9Xj4KxFE2JOax6d0iFTQkUlAZKc6k7
aSZ9gEkFkVVy+WuHP6gb84RskO2fA880qg6xxpb9/MpDbH5q7dGCWxtjJtwfgNyB
s651UHMCNFW5fvcTkeI3Jz/0gogAvS67jk9gD4MN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additions & 79 deletions master.md

This file was deleted.

7 changes: 0 additions & 7 deletions mod.ts
Expand Up @@ -41,13 +41,6 @@ import { StringService as string_service } from "./src/services/string_service.t

import * as util_members from "./src/util/members.ts";

////////////////////////////////////////////////////////////////////////////////
// FILE MARKER: NAMESPACE - DRASH //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Usage: import { Drash } from "/path/to/drash/mod.ts";
//

export namespace Drash {
// TODO: Remove this when the docs don't need it
export namespace Util {
Expand Down
21 changes: 13 additions & 8 deletions src/compilers/template_engine.ts
@@ -1,7 +1,6 @@
const decoder = new TextDecoder();

export class TemplateEngine {

/**
* @description
* A property to hold the base path to the template(s).
Expand Down Expand Up @@ -38,26 +37,32 @@ export class TemplateEngine {
public render(template: string, data: any): string {
let code: any = "with(obj) { var r=[];\n";
let cursor: any = 0;
let html: string = decoder.decode(Deno.readFileSync(this.views_path + template));
let html: string = decoder.decode(
Deno.readFileSync(this.views_path + template),
);
let match: any;
// Check if the template extends another template
let extended = html.match(/<% extends.* %>/g);
if (extended) {
extended.forEach((m: any, i: number) => {
html = html.replace(m, "");
let template = m.replace("<% extends(\"", "")
.replace("\") %>", "");
template = decoder.decode(Deno.readFileSync(this.views_path + template));
let template = m.replace('<% extends("', "")
.replace('") %>', "");
template = decoder.decode(
Deno.readFileSync(this.views_path + template),
);
html = template.replace("<% yield %>", html);
});
}
// Check for partials
let partials: any;
while (partials = html.match(/<% include_partial.* %>/g)) {
partials.forEach((m: any, i: number) => {
let template = m.replace("<% include_partial(\"", "")
.replace("\") %>", "");
template = decoder.decode(Deno.readFileSync(this.views_path + template));
let template = m.replace('<% include_partial("', "")
.replace('") %>', "");
template = decoder.decode(
Deno.readFileSync(this.views_path + template),
);
html = html.replace(m, template);
});
}
Expand Down
30 changes: 24 additions & 6 deletions src/core_loggers/logger.ts
Expand Up @@ -87,7 +87,10 @@ export abstract class Logger {
* The log message.
*/
public debug(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("debug"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("debug"),
message,
);
}

/**
Expand All @@ -98,7 +101,10 @@ export abstract class Logger {
* The log message.
*/
public error(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("error"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("error"),
message,
);
}

/**
Expand All @@ -109,7 +115,10 @@ export abstract class Logger {
* The log message.
*/
public fatal(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("fatal"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("fatal"),
message,
);
}

/**
Expand All @@ -120,7 +129,10 @@ export abstract class Logger {
* The log message.
*/
public info(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("info"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("info"),
message,
);
}

/**
Expand All @@ -131,7 +143,10 @@ export abstract class Logger {
* The log message.
*/
public trace(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("trace"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("trace"),
message,
);
}

/**
Expand All @@ -142,7 +157,10 @@ export abstract class Logger {
* The log message.
*/
public warn(message: string): string | void {
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("warn"), message);
return this.sendToWriteMethod(
Drash.Dictionaries.LogLevels.get("warn"),
message,
);
}

// FILE MARKER: METHODS - PROTECTED //////////////////////////////////////////
Expand Down

0 comments on commit 1196f92

Please sign in to comment.