Permalink
Browse files

feature: HTTPS support

  • Loading branch information...
MikeMitterer committed Dec 6, 2016
1 parent 7f01b95 commit 50ff854945f14e18b68736127194408e9024bc7f
View
@@ -14,3 +14,4 @@ packages
.pub
refreshChromium-1.0.applescript
*.lock
downloads/
View
@@ -1,8 +1,23 @@
# SiteGen
Static site generator. Includes a webserver, sass + autoprefix support
> Static site generator. Includes a webserver, sass + autoprefix support
> Wants to be Jekyll for Dart
Before you read on - check out this [video](https://www.youtube.com/watch?v=smf1uvy0yNQ):
[![ScreenShot](https://github.com/MikeMitterer/dart-sitegen/blob/master/assets/screenshot.jpg?raw=true)](https://www.youtube.com/watch?v=smf1uvy0yNQ)
### New
Support for SASS_PATH added!
#### Support for https-connection!
This is absolutely mandatory if your REST-Server
uses [HTTP Strict Transport Security (HSTS)](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security)
[Here](https://github.com/MikeMitterer/dart-sitegen/blob/master/samples/simple/.sitegen/site.yaml)
you can see the necessary configuration for HTTPS-Support
Generate a self-signed certificate, name it dart.cert and dart.key, place it under <project root>/etc
and run `sitegen -x --usesec` and - voila. That's it!
#### Support for SASS_PATH
[Understanding and Using Sass Load Paths](http://technology.customink.com/blog/2014/10/09/understanding-and-using-sass-load-paths/)
These settings in your .sitegen/site.yaml ()
@@ -42,10 +57,7 @@ chrome extension for maximum productivity.
Under [sitegen.mikemitterer.at](http://sitegen.mikemitterer.at) you can see the result!
Before you read on - check out this [video](http://goo.gl/uUTg8s):
[![ScreenShot](https://github.com/MikeMitterer/dart-sitegen/blob/master/assets/screenshot.jpg?raw=true)](http://goo.gl/uUTg8s)
[Download](https://github.com/MikeMitterer/dart-sitegen/tree/master/dowloads/simple.tgz) the sample structure.
```
├── .sitegen
View
BIN +524 Bytes (100%) assets/screenshot.jpg
Binary file not shown.
View
@@ -88,8 +88,7 @@ class Application {
if (argResults.wasParsed(Options._ARG_SERVE) || argResults.wasParsed(Options._ARG_WATCH_AND_SERVE)) {
foundOptionToWorkWith = true;
final String port = config.port;
serve(config.docroot, port, config.ip);
serve(config);
}
if (!foundOptionToWorkWith) {
@@ -104,11 +103,14 @@ class Application {
}
}
void serve(final String folder, final String port, final String ip) {
Validate.notBlank(folder);
Validate.notBlank(port);
void serve(final Config config) {
Validate.notBlank(config.ip);
Validate.notBlank(config.docroot);
Validate.notBlank(config.port);
final String MY_HTTP_ROOT_PATH = folder; //Platform.script.resolve(folder).toFilePath();
final String ip = config.ip;
final String port = config.port;
final String MY_HTTP_ROOT_PATH = config.docroot; //Platform.script.resolve(folder).toFilePath();
VirtualDirectory virtDir;
void _directoryHandler(final Directory dir,final HttpRequest request) {
@@ -126,9 +128,23 @@ class Application {
final Packages packages = new Packages();
Future<HttpServer> connect;
if(config.usesecureconnection) {
final SecurityContext context = new SecurityContext();
context.useCertificateChain(config.certfile);
context.usePrivateKey(config.keyfile);
connect = HttpServer.bindSecure(ip,int.parse(port),context);
_logger.info('Using a secure connection on $ip - Scheme should be https!');
} else {
connect = HttpServer.bind(ip, int.parse(port));
}
runZoned(() {
HttpServer.bind(ip, int.parse(port)).then( (final HttpServer server) {
_logger.info('Server running on port: $port, $MY_HTTP_ROOT_PATH');
//HttpServer.bindSecure(ip,int.parse(port),context)
//HttpServer.bind(ip, int.parse(port))
connect.then( (final HttpServer server) {
_logger.info('Server running $ip on port: $port, $MY_HTTP_ROOT_PATH');
server.listen( (final HttpRequest request) {
if(request.uri.path.startsWith("/packages")) {
final List<String> parts = request.uri.path.split(new RegExp(r"(?:/|\\)"));
@@ -138,9 +154,9 @@ class Application {
final Package package = packages.resolvePackageUri(
Uri.parse("package:${packageName}")
);
final Uri newUri = Uri.parse("${package.lib.path}/$path");
final String rewritten = "${package.lib.path}/$path".replaceFirst(new RegExp(r"^.*pub\.dartlang\.org/"),"package:");
_logger.info("${request.connectionInfo.remoteAddress.address}:${request.connectionInfo.localPort} - ${request.method} [Rewritten] ${newUri}");
_logger.info("${request.connectionInfo.remoteAddress.address}:${request.connectionInfo.localPort} - ${request.method} [Rewritten] ${rewritten}");
virtDir.serveFile(new File("${package.lib.path}/$path"),request);
} else {
View
@@ -9,25 +9,29 @@ class Config {
static const String _CONFIG_FOLDER = ".sitegen";
static const _CONF_CONTENT_DIR = 'content_dir';
static const _CONF_TEMPLATE_DIR = 'template_dir';
static const _CONF_OUTPUT_DIR = 'output_dir';
static const _CONF_DATA_DIR = 'data_dir';
static const _CONF_PARTIALS_DIR = 'partials_dir';
static const _CONF_ASSETS_DIR = 'assets_dir';
static const _CONF_WORKSPACE_DIR = 'workspace';
static const _CONF_DATE_FORMAT = 'date_format';
static const _CONF_YAML_DELIMITER = 'yaml_delimeter';
static const _CONF_USE_MARKDOWN = 'use_markdown';
static const _CONF_DEFAULT_TEMPLATE = 'default_template';
static const _CONF_SITE_OPTIONS = 'site_options';
static const _CONF_SASS_COMPILER = 'sasscompiler';
static const _CONF_SASS_PATH = 'sass_path';
static const _CONF_USE_SASS = 'usesass';
static const _CONF_USE_AUTOPREFIXER = 'autoprefixer';
static const _CONF_TALK_TO_ME = 'talktome';
static const _CONF_BROWSER = 'browser';
static const _CONF_PORT = 'port';
static const _CONF_CONTENT_DIR = 'content_dir';
static const _CONF_TEMPLATE_DIR = 'template_dir';
static const _CONF_OUTPUT_DIR = 'output_dir';
static const _CONF_DATA_DIR = 'data_dir';
static const _CONF_PARTIALS_DIR = 'partials_dir';
static const _CONF_ASSETS_DIR = 'assets_dir';
static const _CONF_WORKSPACE_DIR = 'workspace';
static const _CONF_DATE_FORMAT = 'date_format';
static const _CONF_YAML_DELIMITER = 'yaml_delimeter';
static const _CONF_USE_MARKDOWN = 'use_markdown';
static const _CONF_DEFAULT_TEMPLATE = 'default_template';
static const _CONF_SITE_OPTIONS = 'site_options';
static const _CONF_SASS_COMPILER = 'sasscompiler';
static const _CONF_SASS_PATH = 'sass_path';
static const _CONF_USE_SASS = 'usesass';
static const _CONF_USE_AUTOPREFIXER = 'autoprefixer';
static const _CONF_TALK_TO_ME = 'talktome';
static const _CONF_BROWSER = 'browser';
static const _CONF_PORT = 'port';
static const _CONF_USE_SECURE_CONNECTION = 'usesec';
static const _CONF_CERT_FILE = 'cert_file';
static const _CONF_KEY_FILE = 'key_file';
static const _CONF_ADDITIONAL_WATCH_FOLDER1 = "watchfolder1";
static const _CONF_ADDITIONAL_WATCH_FOLDER2 = "watchfolder2";
@@ -41,34 +45,41 @@ class Config {
Config(this._argResults) {
_settings[Options._ARG_LOGLEVEL] = 'info';
_settings[Options._ARG_LOGLEVEL] = 'info';
_settings[Config._CONF_CONTENT_DIR] = '${_CONFIG_FOLDER}/html/_content';
_settings[Config._CONF_TEMPLATE_DIR] = '${_CONFIG_FOLDER}/html/_templates';
_settings[Config._CONF_DATA_DIR] = '${_CONFIG_FOLDER}/html/_data';
_settings[Config._CONF_PARTIALS_DIR] = '${_CONFIG_FOLDER}/html/_partials';
_settings[Config._CONF_ASSETS_DIR] = '${_CONFIG_FOLDER}/html/_assets';
_settings[Config._CONF_CONTENT_DIR] = '${_CONFIG_FOLDER}/html/_content';
_settings[Config._CONF_TEMPLATE_DIR] = '${_CONFIG_FOLDER}/html/_templates';
_settings[Config._CONF_DATA_DIR] = '${_CONFIG_FOLDER}/html/_data';
_settings[Config._CONF_PARTIALS_DIR] = '${_CONFIG_FOLDER}/html/_partials';
_settings[Config._CONF_ASSETS_DIR] = '${_CONFIG_FOLDER}/html/_assets';
_settings[Config._CONF_OUTPUT_DIR] = 'web';
_settings[Config._CONF_WORKSPACE_DIR] = '.';
_settings[Config._CONF_DATE_FORMAT] = 'dd.MM.yyyy';
_settings[Config._CONF_YAML_DELIMITER] = '~~~';
_settings[Config._CONF_USE_MARKDOWN] = true;
_settings[Config._CONF_DEFAULT_TEMPLATE] = "default.html";
_settings[Config._CONF_SASS_COMPILER] = "sassc";
_settings[Config._CONF_SASS_PATH] = "";
_settings[Config._CONF_BROWSER] = "Chromium";
_settings[Config._CONF_OUTPUT_DIR] = 'web';
_settings[Config._CONF_WORKSPACE_DIR] = '.';
_settings[Config._CONF_DATE_FORMAT] = 'dd.MM.yyyy';
_settings[Config._CONF_YAML_DELIMITER] = '~~~';
_settings[Config._CONF_USE_MARKDOWN] = true;
_settings[Config._CONF_DEFAULT_TEMPLATE] = "default.html";
_settings[Config._CONF_SASS_COMPILER] = "sassc";
_settings[Config._CONF_SASS_PATH] = "";
_settings[Config._CONF_BROWSER] = "Chromium";
_settings[Config._CONF_SITE_OPTIONS] = <String,String>{};
_settings[Config._CONF_BROWSER] = "Chromium";
_settings[Options._ARG_IP] = "127.0.0.1";
_settings[Config._CONF_PORT] = "8080";
_settings[Config._CONF_SITE_OPTIONS] = <String,String>{};
_settings[Options._ARG_DOCROOT] = _settings[Config._CONF_OUTPUT_DIR]; // web
_settings[Options._ARG_IP] = "127.0.0.1";
_settings[Config._CONF_PORT] = "8080";
_settings[Config._CONF_USE_SASS] = true;
_settings[Config._CONF_USE_AUTOPREFIXER] = true;
_settings[Config._CONF_TALK_TO_ME] = _runsOnOSX();
_settings[Options._ARG_DOCROOT] = _settings[Config._CONF_OUTPUT_DIR]; // web
_settings[Config._CONF_USE_SASS] = true;
_settings[Config._CONF_USE_AUTOPREFIXER] = true;
_settings[Config._CONF_USE_SECURE_CONNECTION] = false;
_settings[Config._CONF_CERT_FILE] = 'dart.crt';
_settings[Config._CONF_KEY_FILE] = 'dart.key';
_settings[Config._CONF_TALK_TO_ME] = _runsOnOSX();
_settings[Config._CONF_ADDITIONAL_WATCH_FOLDER1] = "";
_settings[Config._CONF_ADDITIONAL_WATCH_FOLDER2] = "";
@@ -124,6 +135,11 @@ class Config {
bool get useautoprefixer => _settings[Config._CONF_USE_AUTOPREFIXER];
bool get usesecureconnection => _settings[Config._CONF_USE_SECURE_CONNECTION];
String get certfile => _settings[Config._CONF_CERT_FILE];
String get keyfile => _settings[Config._CONF_KEY_FILE];
bool get talktome => _settings[Config._CONF_TALK_TO_ME];
String get browser => _settings[Config._CONF_BROWSER];
@@ -153,6 +169,11 @@ class Config {
settings["Use markdown"] = usemarkdown ? "yes" : "no";
settings["Use SASS"] = usesass ? "yes" : "no";
settings["Use Autoprefixer"] = useautoprefixer ? "yes" : "no";
settings["Use secure connection"] = usesecureconnection ? "yes" : "no";
settings["Cert-file for secure connection"] = certfile;
settings["Key-file for secure connection"] = keyfile;
settings["Talk to me"] = talktome ? "yes" : "no";
settings["Site options"] = siteoptions.toString();
@@ -246,6 +267,10 @@ class Config {
_settings[Config._CONF_USE_AUTOPREFIXER] = _argResults[Options._ARG_USE_AUTOPREFIXER];
}
if(_argResults.wasParsed(Options._ARG_USE_SECURE_CONNECTION)) {
_settings[Config._CONF_USE_SECURE_CONNECTION] = _argResults[Options._ARG_USE_SECURE_CONNECTION];
}
if(_argResults.wasParsed(Options._ARG_TALK_TO_ME)) {
_settings[Config._CONF_TALK_TO_ME] = _argResults[Options._ARG_TALK_TO_ME];
}
View
@@ -19,6 +19,7 @@ class Options {
static const _ARG_USE_SASS = 'usesass';
static const _ARG_USE_AUTOPREFIXER = 'useapfx';
static const _ARG_USE_SECURE_CONNECTION = 'usesec';
static const _ARG_TALK_TO_ME = 'talktome';
final ArgParser _parser;
@@ -42,6 +43,7 @@ class Options {
print(" 'Generates all basic files and folders: '$APPNAME -i'");
print(" 'Observes the default dirs and serves the web-folder: '$APPNAME -w --serve'");
print(" 'Observes the default dirs and serves the web-folder: '$APPNAME -x'");
print(" 'Serve your site via https: '$APPNAME -x --usesec'");
print(" 'Generates the static site in your 'web-folder': '$APPNAME -g'");
print("");
}
@@ -71,6 +73,8 @@ class Options {
..addFlag(_ARG_USE_AUTOPREFIXER, negatable: true, help: "Enables / disables Autoprefixer", defaultsTo: true)
..addFlag(_ARG_USE_SECURE_CONNECTION, negatable: false, help: "Use secure connection", defaultsTo: false)
..addFlag(_ARG_TALK_TO_ME, negatable: true, help: "Enables / disables Speek-Output", defaultsTo: _runsOnOSX())
..addOption(_ARG_IP, help: "Sets the IP-Address to listen on", defaultsTo: "0.0.0.0")
@@ -1,6 +1,5 @@
title: XTreme
~~~
<div class="mdl-panel mdl-shadow--2dp">
I live in a subfolder
I live in a subfolder <strong>cool</strong>
</div>
@@ -3,7 +3,7 @@
# This is an example of a YAML comment which will be completely ignored.
# A basic variable definition
title: Markdown
title: Markdown2
# A list of strings. Surrounding your strings in quotes is optional,
# but some may require it so they don't interfere with YAML syntax.
@@ -49,11 +49,12 @@ date_format: yMd
### {{title}} (Content)
#### Subheadline
3 `~`'s is the minimum for designating and separating a [YAML][yaml] block, but they can be extended longer -- all that matters
is that the tildes (`~`) are on their own line.
And anything beyond that gets interpreted as [Markdown][markdown]!
You can even use template tags in here, for any variables you set in in the top YAML block, or in your `site.yaml` file:
This post's title is: "{{ title }}"
@@ -63,7 +64,7 @@ This file was last modified on {{ _date }}
Link to [subpages](about/)
Note that variables beginning with an underscore designate *implicit* metadata added by __SiteGen__.
Some vars that are always available by default:
Image: ![Logo](assets/images/ios-desktop.png)
@@ -14,4 +14,4 @@
{"given": "Sally"}
]
}
]
]
@@ -7,4 +7,4 @@
"link" : "Mike Mitterer",
"url" : "http://www.mikemitterer.at/"
}
]
]
@@ -8,4 +8,10 @@ site_options:
author: Mike Mitterer
#browser: Chrome
#browser: Dartium
#browser: Dartium
# Use secure connection
usesec: true
cert_file: etc/dart.crt
key_file: etc/dart.key
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID9DCCAtygAwIBAgIJAIP9bRjfUA+rMA0GCSqGSIb3DQEBCwUAMFkxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0xNjExMjQxMzI3
MjBaFw0xNzExMjQxMzI3MjBaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21l
LVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV
BAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK2A
9uDY2FXacnF0OZWMi2foRmT/xwHaT7gqhy9z34xapZf2mOCOVGlDlYuQqREb5H2W
WScqiaw14H75gYBaeA7icFakUkhhksHOaDMYE+Cdn3xm+wJmjM7kPJpG4hxORs9u
O4NdETfMTWCyYrSRpwDLQxewRjTgCcIn/5rtEcMoJFfwnOvJwDX9lKgX0XJrz2+W
+Penr+IYegFohBuRrwRSLcUvIJa+6EjqViNYqQnC1zucA5+F9z972sZ9ezx0zn8o
bXVcYomjl4Yq/HaKgbFIeVKp57Oivng2SsLu8TyR632gm0EPOvYAYZRFOaCSwcsw
D1gtdQUlF3870Icudh0CAwEAAaOBvjCBuzAdBgNVHQ4EFgQUxlI68qKx7DULMi9f
4JPSkhntRNgwgYsGA1UdIwSBgzCBgIAUxlI68qKx7DULMi9f4JPSkhntRNihXaRb
MFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ
bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMTCWxvY2FsaG9zdIIJAIP9
bRjfUA+rMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAB9yAEqmTu1u
/GiG608uH0ueCOvm3iGuvd0XurQ3JJqKyJb+7AIwVxY44VYl9Skj+l+MOB4CsuED
j4ZS668FWxta085geqAgHL+hIafpS66pCY1e+tUbRWpjCtS989pC+A8NibQsHXp9
1FwtUgPO9Ic12QZBF6UfO38ALqDmMZSUVV9QdfKIY3F9mmo7BRCck+kqS9bMtwO0
eTWVm/ztMcSHTygGlo27PuuLpd+amPbFCDXxw/Pbvxel4Kt7IEhCzuamfNivT6SV
pj7JLumUdPvEa1khOyHWVAnkH+Yj9oTfHu56uTtxj8A6Nj9XzPtLriF5t1dyWAJy
Sm+FZEzU29I=
-----END CERTIFICATE-----
Oops, something went wrong.

0 comments on commit 50ff854

Please sign in to comment.