forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
154 lines (129 loc) · 4.33 KB
/
Startup.cs
File metadata and controls
154 lines (129 loc) · 4.33 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//#define USE_AWS
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Funq;
using ServiceStack;
using ServiceStack.Logging;
using ServiceStack.Host;
using ServiceStack.Text;
using ServiceStack.Api.Swagger;
using ServiceStack.Metadata;
using ServiceStack.Web;
using ServiceStack.IO;
using ServiceStack.Aws.S3;
using Amazon;
using Amazon.S3;
namespace ServiceStack.Core.SelfHost
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Use(async (context, next) => {
Console.WriteLine(context.Request.Path.Value);
await next();
});
app.UseServiceStack(new AppHost());
app.Run(async (context) =>
{
await context.Response.WriteAsync("Unhandled Request!");
});
}
}
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
[FallbackRoute("/{Path*}")]
public class Error404
{
public string Path { get; set; }
}
[Route("/test")]
public class Test : IReturn<string> { }
public class MyServices : Service
{
public object Any(Hello request) =>
new HelloResponse { Result = $"Hello, {request.Name ?? "World"}!" };
//Uncomment to process Unhandled requests
//public object Any(Error404 request) => request;
public UploadStreamResponse Any(UploadStream request)
{
return new UploadStreamResponse();
}
public object Any(Test request)
{
var r = new JsonMetadataHandler();
var response = r.CreateResponse(typeof(Stream));
return response;
}
public object Any(TestRequest request) => new TestResponse();
}
[Api("Test request")]
[Route("/test/{Input}", "GET")]
[Route("/test")]
public class TestRequest : IReturn<TestResponse>
{
[ApiMember(Name = "Parameter name", Description = "Parameter Description",
ParameterType = "body", DataType = "string", IsRequired = true)]
public string Input { get; set; }
}
public class TestResponse
{
public string Output { get; set; }
}
[Route("/uploadStream", "POST", Summary = "Upload stream")]
public class UploadStream : IReturn<UploadStreamResponse>, IRequiresRequestStream
{
public Stream RequestStream { get; set; }
}
public class UploadStreamResponse { }
public class AppHost : AppHostBase
{
public AppHost()
: base(".NET Core Test", typeof(MyServices).GetAssembly()) { }
public override void Configure(Container container)
{
#if USE_AWS
var s3Client = new AmazonS3Client(
Environment.GetEnvironmentVariable("S3_ACCESS_KEY"),
Environment.GetEnvironmentVariable("S3_SECRET_KEY"),
RegionEndpoint.USEast1);
VirtualFiles = new S3VirtualFiles(s3Client, "s3-postgresql");
#endif
SetConfig(new HostConfig {
DebugMode = true,
AdminAuthSecret = Environment.GetEnvironmentVariable("AUTH_SECRET"),
});
Plugins.Add(new TemplatePagesFeature {
EnableDebugTemplateToAll = true,
});
Plugins.Add(new SwaggerFeature());
}
public override List<IVirtualPathProvider> GetVirtualFileSources()
{
var fileSources = base.GetVirtualFileSources();
fileSources.Add(VirtualFiles);
return fileSources;
}
}
}