forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (93 loc) · 3.63 KB
/
Copy pathProgram.cs
File metadata and controls
110 lines (93 loc) · 3.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Check.ServiceModel;
using Funq;
using ServiceStack;
using ServiceStack.Admin;
using ServiceStack.Api.OpenApi;
using ServiceStack.Auth;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using ServiceStack.Text;
using ServiceStack.Web;
namespace CheckHttpListener
{
public class AppSelfHost : AppSelfHostBase
{
public static Rockstar[] SeedRockstars = new[] {
new Rockstar { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 },
new Rockstar { Id = 2, FirstName = "Jim", LastName = "Morrison", Age = 27 },
new Rockstar { Id = 3, FirstName = "Kurt", LastName = "Cobain", Age = 27 },
new Rockstar { Id = 4, FirstName = "Elvis", LastName = "Presley", Age = 42 },
new Rockstar { Id = 5, FirstName = "David", LastName = "Grohl", Age = 44 },
new Rockstar { Id = 6, FirstName = "Eddie", LastName = "Vedder", Age = 48 },
new Rockstar { Id = 7, FirstName = "Michael", LastName = "Jackson", Age = 50 },
};
public AppSelfHost()
: base("DocuRec Services", typeof(TestService).Assembly)
{ }
public override void Configure(Container container)
{
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<Rockstar>();
db.InsertAll(SeedRockstars);
}
Plugins.Add(new SharpPagesFeature());
Plugins.Add(new OpenApiFeature());
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
Plugins.Add(new AdminFeature());
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new[] { new BasicAuthProvider(AppSettings) })
{
//ServiceRoutes = new Dictionary<Type, string[]> {
// { typeof(AuthenticateService), new[] { "/api/auth", "/api/auth/{provider}" } },
//}
});
Plugins.Add(new RequestLogsFeature());
SetConfig(new HostConfig
{
// HandlerFactoryPath = "api",
CompressFilesWithExtensions = { "js", "css" },
// (optional), only compress .js or .css files > 10k
CompressFilesLargerThanBytes = 10 * 1024,
DebugMode = false
});
}
public override string ResolvePathInfo(IRequest request, string originalPathInfo) =>
base.ResolvePathInfo(request, originalPathInfo.Replace("/testsite", "/TestSite"));
// public override RouteAttribute[] GetRouteAttributes(Type requestType)
// {
// var routes = base.GetRouteAttributes(requestType);
// routes.Each(x => x.Path = "/api" + x.Path);
// return routes;
// }
}
[Route("/query/rockstars")]
public class QueryRockstars : QueryDb<Rockstar> { }
//public class Hello { }
public class TestService : Service
{
//public object Any(Hello request)
//{
// return request;
//}
}
internal class Program
{
private static void Main(string[] args)
{
var baseUrl = "http://localhost:8000/";
var appHost = new AppSelfHost()
.Init()
.Start(baseUrl);
Console.WriteLine(baseUrl);
Process.Start(baseUrl);
Console.ReadLine();
}
}
}