Skip to content

Commit 729c11c

Browse files
committed
Work on connect-static
Doesn't work yet.
1 parent ffe731e commit 729c11c

File tree

7 files changed

+104
-3
lines changed

7 files changed

+104
-3
lines changed

Package.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ let package = Package(
1111
],
1212

1313
products: [
14-
.executable(name: "httpd-helloworld", targets: [ "httpd-helloworld" ])
14+
.executable(name: "httpd-helloworld", targets: [ "httpd-helloworld" ]),
15+
.executable(name: "connect-static", targets: [ "connect-static" ])
1516
],
1617

1718
dependencies: [
1819
.package(url: "https://github.com/Macro-swift/Macro.git",
20+
from: "0.0.12"),
21+
/*
22+
.package(url: "https://github.com/Macro-swift/MacroExpress.git",
1923
from: "0.0.2")
24+
*/
25+
.package(url: "file:///Users/helge/dev/Swift/Macro/MacroExpress",
26+
.branch("develop"))
2027
],
2128

2229
targets: [
23-
.target(name: "httpd-helloworld", dependencies: [ "Macro" ])
30+
.target(name: "httpd-helloworld", dependencies: [ "Macro" ]),
31+
.target(name: "connect-static", dependencies: [ "MacroExpress" ])
2432
]
2533
)

Sources/connect-static/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2>Macro.swift connect-static
2+
<img src="http://zeezide.com/img/MicroExpressIcon1024.png"
3+
align="right" width="100" height="100" />
4+
</h2>
5+
6+
Demonstrates the use of the `connect.serveStatic` middleware.
7+
8+
## Running the Sample
9+
10+
If you have
11+
[swift-sh](https://github.com/mxcl/swift-sh)
12+
installed (`brew install swift-sh`),
13+
just starting the main.swift file works:
14+
```
15+
$ Sources/connect-static/main.swift
16+
2020-01-07T17:14:35+0100 notice: Server listening on http://localhost:1337/
17+
```
18+
19+
Or you can use `swift run` w/o installing additional software:
20+
```
21+
$ swift run connect-static
22+
2020-01-07T21:37:05+0100 notice: Server listening on http://localhost:1337/
23+
```
24+
25+
### Who
26+
27+
**Macro** is brought to you by
28+
the
29+
[Always Right Institute](http://www.alwaysrightinstitute.com)
30+
and
31+
[ZeeZide](http://zeezide.de).
32+
We like
33+
[feedback](https://twitter.com/ar_institute),
34+
GitHub stars,
35+
cool [contract work](http://zeezide.com/en/services/services.html),
36+
presumably any form of praise you can think of.
37+
38+
There is a `#microexpress` channel on the
39+
[Noze.io Slack](http://slack.noze.io/). Feel free to join!

Sources/connect-static/main.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/swift sh
2+
3+
import Foundation
4+
import MacroExpress // @Macro-swift ~> 0.0.2
5+
6+
let dirname = __dirname()
7+
8+
let app = connect()
9+
10+
app.use { req, _, next in
11+
print("request:", req.url)
12+
next()
13+
}
14+
15+
app.use(logger("dev")) // Middleware: logs the request
16+
17+
let servePath = __dirname() + "/public"
18+
console.log("serving:", servePath)
19+
app.use(serveStatic(__dirname() + "/public"))
20+
21+
app.listen(1337) {
22+
console.log("Server listening on http://localhost:1337/")
23+
}
70.8 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<title>Macro</title>
4+
</head>
5+
<body>
6+
<center><img src="images/logo.svg" width="256" height="256" /></center>
7+
8+
<p>Bacon ipsum dolor amet pancetta shankle jerky pork loin venison tri-tip, cupim pastrami capicola beef. Kielbasa swine biltong, jerky corned beef pig pork filet mignon fatback chicken hamburger ball tip. Swine pork belly beef ribs spare ribs kevin pancetta shank beef jerky chuck shoulder capicola tongue pork. Alcatra swine ribeye, kielbasa landjaeger corned beef beef ribs venison fatback bresaola andouille capicola pig meatloaf. Pork loin andouille venison ball tip, kielbasa tenderloin beef ribs biltong prosciutto rump. Short ribs flank boudin strip steak tenderloin brisket andouille kielbasa pork loin rump salami fatback. Sausage pork pork belly ball tip chicken biltong tri-tip hamburger cupim tenderloin pancetta.</p>
9+
10+
<p>Corned beef andouille short loin meatloaf. Brisket pork turkey picanha short loin, shank bacon andouille drumstick ham pancetta. Ball tip pork chop chicken, tenderloin chuck jerky tongue short ribs strip steak pig turkey landjaeger frankfurter ribeye pancetta. Kielbasa shank pancetta tongue frankfurter bresaola. Strip steak drumstick sausage landjaeger pork belly tongue venison cupim prosciutto pork beef ham corned beef. Chuck beef landjaeger venison, meatloaf sirloin biltong fatback chicken strip steak pork chop. Ham hock chuck bacon, salami cow pork loin pig beef picanha corned beef brisket doner frankfurter.</p>
11+
</body>
12+
</html>

Sources/httpd-helloworld/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/swift sh
22

3-
import Macro // @Macro-swift ~> 0.0.2
3+
import Macro // @Macro-swift ~> 0.0.12
44

55
http.createServer { req, res in
66
// log request

0 commit comments

Comments
 (0)