public
Description: A cross-platform web server that's scripted with Nu.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nunja.git
nunja / nunjad
100755 68 lines (56 sloc) 2.214 kb
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
#!/usr/local/bin/nush
#
# @file nunjad
# The Nunja daemon.
#
# @copyright Copyright (c) 2008 Neon Design Technology, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
(load "Nunja")
 
(set exit (NuBridgedFunction functionWithName:"exit" signature:"vi"))
 
;;;;;;;;;;;;;;;;;;;;;;;;;
;; main program
;;;;;;;;;;;;;;;;;;;;;;;;;
 
(set argv ((NSProcessInfo processInfo) arguments))
(set argi 0)
 
;; if we're running as a nush script, skip the nush path
(if (/(.*)nush$/ findInString:(argv 0))
    (set argi (+ argi 1)))
 
;; skip the program name
(set argi (+ argi 1))
 
;; the option(s) we need to set
(set site nil)
(set port 3000)
 
;; process the remaining arguments
(while (< argi (argv count))
       (case (argv argi)
             ("-s" (set argi (+ argi 1)) (set site (argv argi)))
             ("--site" (set argi (+ argi 1)) (set site (argv argi)))
             ("-p" (set argi (+ argi 1)) (set port ((argv argi) intValue)))
             ("--port" (set argi (+ argi 1)) (set port ((argv argi) intValue)))
   ("-l" (Nunja setLocalOnly:YES))
   ("--local" (Nunja setLocalOnly:YES))
             ("-v" (Nunja setVerbose:YES))
             ("--verbose" (Nunja setVerbose:YES))
             (else (puts (+ "unknown option: " (argv argi)))
                   (exit -1)))
       (set argi (+ argi 1)))
 
(set n ((Nunja alloc) init))
(if (Nunja localOnly)
    (then (n bindToAddress:"127.0.0.1" port:port))
    (else (n bindToAddress:"0.0.0.0" port:port)))
 
(if site
    (n setDelegate:((NunjaDelegate alloc) initWithSite:site)))
(puts (+ "Nunja is running on port " port))
(set $site site) ;; make the path to the site directory available to handlers
(n run)