-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeb.config
80 lines (80 loc) · 3.97 KB
/
Web.config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
This configuration is designed to run a documental Node.js application using Microsoft IIS as a reverse proxy.
You can, of course, run the application in other environments without a Web.config file.
Prerequisites:
1. iisnode (https://github.com/Azure/iisnode) must be installed.
2. In IIS, go to docs.gaois.ie > URL Rewrite > View Server Variables and add a new variable entitled
`HTTP_X_FORWARDED_PROTO` if one does not already exist. You will need to do this for any further server
variables that you wish to pass to the application (see below).
-->
<appSettings>
<!--
App settings configured here are passed to the Node.js application by iisnode as environment variables:
the `HOSTNAME` setting defined below will be accessible in the Node.js application as `process.env.HOSTNAME`.
The HOSTNAME variable is required in a server environment and should match the website's public host name.
-->
<add key="ANALYTICS_ID" value="UA-565316-27" />
<add key="HOSTNAME" value="docs.gaois.ie" />
</appSettings>
<system.webServer>
<handlers>
<!--
Tells iisnode to handle requests made to app.js.
For documental app.js is a one-line JS file: `require('./__sapper__/build/index.js');`
This calls the server-side application code.
-->
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!--
This is a typical HTTP > HTTPS redirect for production environments.
We also add an IIS server variable (see `<serverVariables>` below).
TLS terminates at IIS and by default the Node.js server sitting on the other side of the proxy
has no awareness of several features of the original HTTP request, e.g. the protocol (e.g. HTTP or HTTPS).
We can pass such information to Node.js by means of server variables.
Server variables prefixed `HTTP_` in IIS are passed to the application as HTTP headers.
The server variable `HTTP_X_FORWARDED_PROTO` is then accessible to Node.js as `req.headers['x-forwarded-proto']`.
For the rule below we know the forwarded protocol will be `https`.
-->
<rule name="HTTP to Prod HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
<serverVariables>
<set name="HTTP_X_FORWARDED_PROTO" value="https" />
</serverVariables>
</rule>
<!--
This rule rewrites all requests to app.js, where they are handled by the application server code (see above).
In addition, we again forward the original request protocol (HTTP|(S)) by means of an IIS server variable.
We use a Rewrite Map to dynamically capture the request protocol (explained below).
-->
<rule name="App">
<match url="/*" />
<action type="Rewrite" url="app.js" />
<serverVariables>
<set name="HTTP_X_FORWARDED_PROTO" value="{MapProtocol:{HTTPS}}" />
</serverVariables>
</rule>
</rules>
<rewriteMaps>
<!--
IIS does not make the request protocol directly available in the same way as `HTTP_HOST`, for example.
Instead, the `HTTPS` variable returns either `on` or `off` with respect to the protocol.
We use a Rewrite Map, entitled `MapProtocol` here, to obtain the protocol value which populates the
`HTTP_X_FORWARDED_PROTO` variable above.
-->
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>