Skip to content

Commit 14c7e00

Browse files
committed
Connect-static works now
A very basic example demonstrating how a directory can be served locally.
1 parent adba53e commit 14c7e00

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717

1818
dependencies: [
1919
.package(url: "https://github.com/Macro-swift/Macro.git",
20-
from: "0.0.15"),
20+
from: "0.0.16"),
2121
.package(url: "https://github.com/Macro-swift/MacroExpress.git",
2222
from: "0.0.3")
2323
],

Sources/connect-static/main.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ let dirname = __dirname()
77

88
let app = connect()
99

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)
10+
app.use(logger("dev"))
1911
app.use(serveStatic(__dirname() + "/public"))
2012

13+
app.use { req, res, next in
14+
guard req.url == "/" else { return next() }
15+
res.redirect("/index.html")
16+
}
17+
2118
app.listen(1337) {
22-
console.log("Server listening on http://localhost:1337/")
19+
console.log("Server listening on http://localhost:1337")
2320
}

Sources/connect-static/public/images/logo.svg

Lines changed: 0 additions & 19 deletions
This file was deleted.

Sources/connect-static/public/index.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
<html>
22
<head>
33
<title>Macro</title>
4+
<style>
5+
html { background: #FFFFFF; }
6+
body {
7+
color: #383838;
8+
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
9+
line-height: 1.5rem;
10+
margin: 0 auto;
11+
}
12+
p {
13+
margin-left: 1rem;
14+
margin-right: 1rem;
15+
}
16+
a { text-decoration: none; }
17+
</style>
418
</head>
519
<body>
6-
<center><img src="images/logo.svg" width="256" height="256" /></center>
20+
21+
<p>
22+
<center>
23+
<img src="images/logo256x256.png" width="256" height="256" /><br />
24+
<a href="https://github.com/Macro-swift" target="gh">Macro</a>
25+
is brought to you by
26+
<a href="https://zeezide.de/" target="zz">ZeeZide</a>.
27+
</center>
28+
</p>
729

830
<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>
931

0 commit comments

Comments
 (0)