Skip to content

Commit

Permalink
add cors to SetRouter options
Browse files Browse the repository at this point in the history
  • Loading branch information
dancespiele committed Mar 12, 2018
1 parent cf8e78b commit dffbe8f
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 61 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,18 @@ class Greeting {
}
}

const endpoints = [new Greeting()];
const cors = {
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
};

const configRouter: IRouterOptions = {
road: app,
endpoints,
connectionMode: true,
cors,
endpoints,
road: app,
verbose: true,
}
};

new SetRouter(configRouter);
```
Expand All @@ -180,7 +184,10 @@ import {Road, middleware} from "spiel-server";

const app = new Road();

app.use(middleware.cors(['http://localhost:8080'], ['authorization']));
app.use(middleware.cors({
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
}));
```
About the Roads Api see [in Roads docs](https://github.com/Dashron/roads#index)

Expand Down Expand Up @@ -296,8 +303,14 @@ class Greeting {

const endpoints = [new User(), new Greeting()];

const cors = {
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
};

const configRouter: IRouterOptions = {
connectionMode: true,
cors,
endpoints,
road: app,
verbose: true,
Expand Down
23 changes: 18 additions & 5 deletions READMEAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ class Greeting {
}
}

const endpoints = [new Greeting()];
const cors = {
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
};

const configRouter: IRouterOptions = {
road: app,
endpoints,
connectionMode: true,
cors,
endpoints,
road: app,
verbose: true,
}
};

new SetRouter(configRouter);
```
Expand All @@ -177,7 +181,10 @@ import {Road, middleware} from "spiel-server";

const app = new Road();

app.use(middleware.cors(['http://localhost:8080'], ['authorization']));
app.use(middleware.cors({
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
}));
```
About the Roads Api see [in Roads docs](https://github.com/Dashron/roads#index)

Expand Down Expand Up @@ -293,8 +300,14 @@ class Greeting {

const endpoints = [new User(), new Greeting()];

const cors = {
validOrigins: ['http://localhost:8080'],
responseHeaders: ['content-type']
};

const configRouter: IRouterOptions = {
connectionMode: true,
cors,
endpoints,
road: app,
verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/classes/_server_set_router_.setrouter.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L14">server/set-router.ts:14</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L14">server/set-router.ts:14</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -165,7 +165,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> Router<wbr>Connect<
<div class="tsd-signature tsd-kind-icon">Router<wbr>Connect<span class="tsd-signature-symbol">:</span> <a href="../modules/_server_helpers_interfaces_.html#endpointsconnect" class="tsd-signature-type">EndpointsConnect</a><span class="tsd-signature-symbol"> =&nbsp;[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L11">server/set-router.ts:11</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L11">server/set-router.ts:11</a></li>
</ul>
</aside>
</section>
Expand All @@ -175,7 +175,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> connection<wbr>Mode
<div class="tsd-signature tsd-kind-icon">connection<wbr>Mode<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L13">server/set-router.ts:13</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L13">server/set-router.ts:13</a></li>
</ul>
</aside>
</section>
Expand All @@ -185,7 +185,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> endpoints</h3>
<div class="tsd-signature tsd-kind-icon">endpoints<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_server_helpers_interfaces_.iendpoint.html" class="tsd-signature-type">IEndpoint</a><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L9">server/set-router.ts:9</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L9">server/set-router.ts:9</a></li>
</ul>
</aside>
</section>
Expand All @@ -195,7 +195,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> road</h3>
<div class="tsd-signature tsd-kind-icon">road<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Road</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L12">server/set-router.ts:12</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L12">server/set-router.ts:12</a></li>
</ul>
</aside>
</section>
Expand All @@ -205,7 +205,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> router</h3>
<div class="tsd-signature tsd-kind-icon">router<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">SimpleRouter</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L10">server/set-router.ts:10</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L10">server/set-router.ts:10</a></li>
</ul>
</aside>
</section>
Expand All @@ -215,7 +215,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> verbose</h3>
<div class="tsd-signature tsd-kind-icon">verbose<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L14">server/set-router.ts:14</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L14">server/set-router.ts:14</a></li>
</ul>
</aside>
</section>
Expand All @@ -232,7 +232,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> build<wbr>After<wbr>Mid
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L111">server/set-router.ts:111</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L115">server/set-router.ts:115</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -255,7 +255,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> build<wbr>Before<wbr>Mi
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L105">server/set-router.ts:105</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L109">server/set-router.ts:109</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -278,7 +278,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> getendpoints</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L71">server/set-router.ts:71</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L75">server/set-router.ts:75</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
Expand All @@ -295,7 +295,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> info<wbr>Request</h
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L43">server/set-router.ts:43</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L47">server/set-router.ts:47</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
Expand All @@ -312,7 +312,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> set<wbr>Connection<
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L65">server/set-router.ts:65</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L69">server/set-router.ts:69</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
Expand All @@ -329,7 +329,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> set<wbr>Router<wbr>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/set-router.ts#L50">server/set-router.ts:50</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/set-router.ts#L54">server/set-router.ts:54</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
23 changes: 18 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,18 @@ <h3 id="setting-the-router">Setting the router</h3>
}
}

<span class="hljs-keyword">const</span> endpoints = [<span class="hljs-keyword">new</span> Greeting()];
<span class="hljs-keyword">const</span> cors = {
validOrigins: [<span class="hljs-string">'http://localhost:8080'</span>],
responseHeaders: [<span class="hljs-string">'content-type'</span>]
};

<span class="hljs-keyword">const</span> configRouter: IRouterOptions = {
road: app,
endpoints,
connectionMode: <span class="hljs-literal">true</span>,
cors,
endpoints,
road: app,
verbose: <span class="hljs-literal">true</span>,
}
};

<span class="hljs-keyword">new</span> SetRouter(configRouter);
</code></pre>
Expand All @@ -236,7 +240,10 @@ <h3 id="using-the-roads-api">Using the roads API</h3>

<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Road();

app.use(middleware.cors([<span class="hljs-string">'http://localhost:8080'</span>], [<span class="hljs-string">'authorization'</span>]));
app.use(middleware.cors({
validOrigins: [<span class="hljs-string">'http://localhost:8080'</span>],
responseHeaders: [<span class="hljs-string">'content-type'</span>]
}));
</code></pre>
<p>About the Roads Api see <a href="https://github.com/Dashron/roads#index">in Roads docs</a></p>
<h3 id="complete-example-with-server">Complete example with Server</h3>
Expand Down Expand Up @@ -350,8 +357,14 @@ <h3 id="complete-example-with-server">Complete example with Server</h3>

<span class="hljs-keyword">const</span> endpoints = [<span class="hljs-keyword">new</span> User(), <span class="hljs-keyword">new</span> Greeting()];

<span class="hljs-keyword">const</span> cors = {
validOrigins: [<span class="hljs-string">'http://localhost:8080'</span>],
responseHeaders: [<span class="hljs-string">'content-type'</span>]
};

<span class="hljs-keyword">const</span> configRouter: IRouterOptions = {
connectionMode: <span class="hljs-literal">true</span>,
cors,
endpoints,
road: app,
verbose: <span class="hljs-literal">true</span>,
Expand Down
4 changes: 2 additions & 2 deletions docs/interfaces/_server_helpers_interfaces_.iendpoints.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h3>name</h3>
<div class="tsd-signature tsd-kind-icon">name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L23">server/helpers/interfaces.ts:23</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L23">server/helpers/interfaces.ts:23</a></li>
</ul>
</aside>
</section>
Expand All @@ -109,7 +109,7 @@ <h3>props</h3>
<div class="tsd-signature tsd-kind-icon">props<span class="tsd-signature-symbol">:</span> <a href="_server_helpers_interfaces_.irouteprops.html" class="tsd-signature-type">IRouteProps</a><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L24">server/helpers/interfaces.ts:24</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L24">server/helpers/interfaces.ts:24</a></li>
</ul>
</aside>
</section>
Expand Down
4 changes: 2 additions & 2 deletions docs/interfaces/_server_helpers_interfaces_.iroutemethod.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h3>method</h3>
<div class="tsd-signature tsd-kind-icon">method<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L13">server/helpers/interfaces.ts:13</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L13">server/helpers/interfaces.ts:13</a></li>
</ul>
</aside>
</section>
Expand All @@ -109,7 +109,7 @@ <h3>path</h3>
<div class="tsd-signature tsd-kind-icon">path<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L12">server/helpers/interfaces.ts:12</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L12">server/helpers/interfaces.ts:12</a></li>
</ul>
</aside>
</section>
Expand Down
6 changes: 3 additions & 3 deletions docs/interfaces/_server_helpers_interfaces_.irouteprops.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h3>method</h3>
<div class="tsd-signature tsd-kind-icon">method<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L18">server/helpers/interfaces.ts:18</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L18">server/helpers/interfaces.ts:18</a></li>
</ul>
</aside>
</section>
Expand All @@ -110,7 +110,7 @@ <h3>name</h3>
<div class="tsd-signature tsd-kind-icon">name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L19">server/helpers/interfaces.ts:19</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L19">server/helpers/interfaces.ts:19</a></li>
</ul>
</aside>
</section>
Expand All @@ -120,7 +120,7 @@ <h3>path</h3>
<div class="tsd-signature tsd-kind-icon">path<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/a5e07ed/src/server/helpers/interfaces.ts#L17">server/helpers/interfaces.ts:17</a></li>
<li>Defined in <a href="https://github.com/spieljs/spiel-server/blob/cf8e78b/src/server/helpers/interfaces.ts#L17">server/helpers/interfaces.ts:17</a></li>
</ul>
</aside>
</section>
Expand Down
Loading

0 comments on commit dffbe8f

Please sign in to comment.