1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Configuration of the Web server of xymus.net
23 # Use actions defined by contribs
25 import benitlux_controller
26 import opportunity_controller
28 # Header for the whole site
32 # Current page id, is used to set the `active` class on the header tab
33 var page
: nullable String
35 # Make room for a login or logout placeholder (used by tnitter)
36 var login_placeholder
: Bool
40 var actives
= new HashMap[String, String]
42 if page
!= null then actives
[page
] = " class=\"active\
""
45 <nav class="navbar navbar-default" role="navigation">
46 <div class="container-fluid">
47 <div class="navbar-header">
48 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
49 <span class="sr-only">Toggle navigation</span>
50 <span class="icon-bar"></span>
51 <span class="icon-bar"></span>
52 <span class="icon-bar"></span>
54 <a class="navbar-brand" href="http://xymus.net/">Xymus.net</a>
57 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
58 <ul class="nav navbar-nav">
59 <li{{{actives.get_or_default("ens", "")}}}><a href="http://xymus.net/ens/">Enseignement</a></li>
60 <li><a href="http://pep8.xymus.net/">Pep/8 Analysis</a></li>
61 <li{{{actives.get_or_default("tnitter", "")}}}><a href="http://tnitter.xymus.net/">Tnitter</a></li>
62 <li{{{actives.get_or_default("benitlux", "")}}}><a href="http://benitlux.xymus.net/">Benitlux</a></li>
63 <li{{{actives.get_or_default("opportunity", "")}}}><a href="http://xymus.net/opportunity/">Opportunity</a></li>
64 <li><a href="http://nitlanguage.org/">Nit</a></li>
67 <ul class="nav navbar-nav pull-right">
69 if login_placeholder
then add
"%header_right%"
78 redef fun to_s
do return write_to_string
81 class OpportunityMasterHeader
82 super OpportunityHeader
84 var master_header
: MasterHeader
92 <title>Opportunity - The meetup planner</title>
93 <meta charset="utf-8">
94 <meta name="viewport" content="width=device-width, initial-scale=1">
95 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
96 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
97 <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
105 .opportunity-action:hover {
116 redef var header
: String = (new MasterHeader("tnitter", true)).to_s
119 redef class BenitluxDocument
120 redef var header
= new MasterHeader("benitlux", false)
123 redef class ErrorTemplate
124 redef var header
= new MasterHeader(null, false)
127 redef class OpportunityPage
128 redef var header
= new OpportunityMasterHeader(new MasterHeader("opportunity", false))
131 # Avoid executing when running tests
132 if "NIT_TESTING".environ
== "true" then exit
0
134 # Setup server interfaces
136 # Change these to use this config on your own server!
137 var default_vh
= new VirtualHost("xymus.net:80")
138 var vps_vh
= new VirtualHost("vps.xymus.net:80")
139 var tnitter_vh
= new VirtualHost("tnitter.xymus.net:80")
140 var pep8_vh
= new VirtualHost("pep8.xymus.net:80")
141 var benitlux_vh
= new VirtualHost("benitlux.xymus.net:80")
143 var factory
= new HttpFactory.and_libevent
144 factory
.config
.virtual_hosts
.add default_vh
145 factory
.config
.virtual_hosts
.add vps_vh
146 factory
.config
.virtual_hosts
.add tnitter_vh
147 factory
.config
.virtual_hosts
.add pep8_vh
148 factory
.config
.virtual_hosts
.add benitlux_vh
150 # Ports are open, drop to a low-privileged user if we are root
151 var user_group
= new UserGroup("nitcorn", "nitcorn")
152 if sys
.uid
== 0 then user_group
.drop_privileges
154 # Tnitter is available at `tnitter.xymus.net` and `xymus.net/tnitter/`
155 var tnitter
= new Tnitter
156 default_vh
.routes
.add
new Route("/tnitter/", tnitter
)
157 tnitter_vh
.routes
.add
new Route(null, tnitter
)
159 # Pep/8 Analysis is only a file server. It is available at `pep8.xymus.net`
160 # and through the global/default file server at `xymus.net/pep8/`
162 # TODO Implement pep8analysis server-side with a nitcorn action
163 pep8_vh
.routes
.add
new Route(null, new FileServer("/var/www/pep8/"))
165 # Benitlux is available at `benitlux.xymus.net` and `xymus.net/benitlux/`
167 # It has 2 actions/Web interfaces. The Web user UI to subscribe and unsubscribe
168 # to the mailing list. And the RESTful interface used by the Android app.
169 var benitlux_sub
= new BenitluxSubscriptionAction
170 var benitlux_rest
= new BenitluxRESTAction
171 default_vh
.routes
.add
new Route("/benitlux/rest/", benitlux_rest
)
172 default_vh
.routes
.add
new Route("/benitlux/", benitlux_sub
)
173 benitlux_vh
.routes
.add
new Route("/rest/", benitlux_rest
)
174 benitlux_vh
.routes
.add
new Route(null, benitlux_sub
)
176 var opportunity
= new OpportunityWelcome
177 var opportunity_rest
= new OpportunityRESTAction
178 default_vh
.routes
.add
new Route("/opportunity/rest/", opportunity_rest
)
179 default_vh
.routes
.add
new Route("/opportunity/", opportunity
)
181 # We use a special file server for the path `xymus.net/ens` only to display
182 # a different header.
183 var file_server_ens
= new FileServer("/var/www/ens/")
184 file_server_ens
.header
= (new MasterHeader("ens", false))
185 default_vh
.routes
.add
new Route("/ens/", file_server_ens
)
187 # Default file server is used for the main page at `xymus.net` and it is
188 # the default action for any path not caught by other actions.
189 var file_server
= new FileServer("/var/www/")
190 file_server
.header
= (new MasterHeader(null, false))
191 default_vh
.routes
.add
new Route(null, file_server
)
192 vps_vh
.routes
.add
new Route(null, file_server
)
194 # Launch server main loop