Skip to content

Commit 87542b7

Browse files
authored
Merge pull request #8 from tayloraswift/package-indexing
add production authority
2 parents 9c48e70 + 1c21f3c commit 87542b7

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

Assets/robots.txt

Whitespace-only changes.

Sources/UnidocPages/Templates/Site.Asset.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension Site
1818

1919
case main_js = "main.js"
2020
case main_js_map = "main.js.map"
21+
22+
case robots_txt = "robots.txt"
2123
}
2224
}
2325
extension Site.Asset:FixedRoot

Sources/UnidocServer/Authorities/ServerAuthority (ext).swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import HTTPServer
22
import NIOSSL
33

4+
extension ServerAuthority where Self == SwiftinitTest
5+
{
6+
static
7+
func swiftinitTest(_ context:NIOSSLContext) -> SwiftinitTest
8+
{
9+
.init(context: context)
10+
}
11+
}
412
extension ServerAuthority where Self == Swiftinit
513
{
614
static

Sources/UnidocServer/Authorities/Swiftinit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension Swiftinit:ServerAuthority
1717
var scheme:ServerScheme { .https }
1818

1919
static
20-
var domain:String { "test.swiftinit.org" }
20+
var domain:String { "swiftinit.org" }
2121

2222
var tls:NIOSSLContext? { self.context }
2323

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import HTTPServer
2+
import NIOSSL
3+
4+
struct SwiftinitTest
5+
{
6+
private
7+
let context:NIOSSLContext
8+
9+
init(context:NIOSSLContext)
10+
{
11+
self.context = context
12+
}
13+
}
14+
extension SwiftinitTest:ServerAuthority
15+
{
16+
static
17+
var scheme:ServerScheme { .https }
18+
19+
static
20+
var domain:String { "test.swiftinit.org" }
21+
22+
var tls:NIOSSLContext? { self.context }
23+
24+
static
25+
func redact(error _:any Error) -> String
26+
{
27+
"(error redacted)"
28+
}
29+
}

Sources/UnidocServer/Caching/Site.Asset (ext).swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ extension Site.Asset:CacheKey
1414
case .literata45_woff2,
1515
.literata47_woff2,
1616
.literata75_woff2,
17-
.literata77_woff2: return .cold
17+
.literata77_woff2,
18+
.robots_txt: return .cold
1819
case .main_css,
1920
.main_js: return nil
2021
case .main_css_map,
@@ -30,6 +31,7 @@ extension Site.Asset:CacheKey
3031
case .literata47_woff2: return ["woff2", "Literata_24pt-Italic.woff2"]
3132
case .literata75_woff2: return ["woff2", "Literata_24pt-Bold.woff2"]
3233
case .literata77_woff2: return ["woff2", "Literata_24pt-BoldItalic.woff2"]
34+
case .robots_txt: return ["robots.txt"]
3335
case .main_css: return ["css", "Main.css"]
3436
case .main_css_map: return ["css", "Main.css.map"]
3537
case .main_js: return ["js", "Main.js"]
@@ -41,6 +43,7 @@ extension Site.Asset:CacheKey
4143
{
4244
switch self
4345
{
46+
case .robots_txt: return .text(.plain, charset: .utf8)
4447
case .literata45_woff2,
4548
.literata47_woff2,
4649
.literata75_woff2,

Sources/UnidocServer/Server/AnyOperation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extension AnyOperation
4040
switch root
4141
{
4242
case Site.Admin.root: return .database(AdminOperation.status)
43+
case "robots.txt": return .datafile(.init(.robots_txt, tag: tag))
4344
case _: return nil
4445
}
4546
}

Sources/UnidocServer/Server/Server.Options.Authority.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ extension Server.Options
55
{
66
enum Authority:String, Equatable, Hashable, Sendable
77
{
8-
case localhost
8+
case production
99
case testing
10+
case localhost
1011
}
1112
}
1213
extension Server.Options.Authority
@@ -15,19 +16,16 @@ extension Server.Options.Authority
1516
{
1617
switch self
1718
{
19+
case .production: return Swiftinit.self
20+
case .testing: return SwiftinitTest.self
1821
case .localhost: return Localhost.self
19-
case .testing: return Swiftinit.self
2022
}
2123
}
2224

2325
func load(certificates:String?) throws -> any ServerAuthority
2426
{
25-
switch self
27+
func context() throws -> NIOSSLContext
2628
{
27-
case .localhost:
28-
return .localhost
29-
30-
case .testing:
3129
guard let directory:String = certificates
3230
else
3331
{
@@ -39,11 +37,16 @@ extension Server.Options.Authority
3937
let privateKey:NIOSSLPrivateKey =
4038
try .init(file: "\(directory)/privkey.pem", format: .pem)
4139

42-
let context:NIOSSLContext = try .init(configuration: .makeServerConfiguration(
40+
return try .init(configuration: .makeServerConfiguration(
4341
certificateChain: certificates.map(NIOSSLCertificateSource.certificate(_:)),
4442
privateKey: .privateKey(privateKey)))
43+
}
4544

46-
return .swiftinit(context)
45+
switch self
46+
{
47+
case .production: return .swiftinit(try context())
48+
case .testing: return .swiftinitTest(try context())
49+
case .localhost: return .localhost
4750
}
4851
}
4952
}

0 commit comments

Comments
 (0)