Skip to content

Commit

Permalink
添加fc支持
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Apr 15, 2020
1 parent 2d9249b commit c9bcd3b
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 40 deletions.
12 changes: 12 additions & 0 deletions MetingJS.Server.Fc/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "3.1.3",
"commands": [
"dotnet-ef"
]
}
}
}
13 changes: 13 additions & 0 deletions MetingJS.Server.Fc/FcRemoteEntrypoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Aliyun.Serverless.Core.Http;
using Microsoft.AspNetCore.Hosting;

namespace MetingJS.Server.Fc
{
public class FcRemoteEntrypoint : FcHttpEntrypoint
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
}
}
24 changes: 24 additions & 0 deletions MetingJS.Server.Fc/MetingJS.Server.Fc.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;NETCORE21</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;NETCORE21</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliyun.Serverless.Core.Http" Version="1.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MetingJS.Server\MetingJS.Server.csproj" />
</ItemGroup>


</Project>
10 changes: 10 additions & 0 deletions MetingJS.Server.Fc/MetingJS.Server.Fc.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>MetingJS.Server.Fc</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>
23 changes: 23 additions & 0 deletions MetingJS.Server.Fc/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace MetingJS.Server.Fc
{
public class Program
{
// public static void Main(string[] args)
// {
// CreateWebHostBuilder(args).Build().Run();
// }
//
// public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
// WebHost.CreateDefaultBuilder(args)
// .UseStartup<Startup>();

public static void Main(string[] args)
{
Console.WriteLine("请不要这样启动");
}
}
}
22 changes: 22 additions & 0 deletions MetingJS.Server.Fc/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
此文件由 Web 项目的发布/打包过程使用。可以通过编辑此 MSBuild 文件
自定义此过程的行为。为了解与此相关的更多内容,请访问 https://go.microsoft.com/fwlink/?LinkID=208121。
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<ProjectGuid>783cd8db-2b6e-477b-a57c-f603d4acfc64</ProjectGuid>
<SelfContained>false</SelfContained>
<publishUrl>bin\Release\netcoreapp2.1\publish\</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
此文件由 Web 项目的发布/打包过程使用。可以通过编辑此 MSBuild 文件
自定义此过程的行为。为了解与此相关的更多内容,请访问 https://go.microsoft.com/fwlink/?LinkID=208121。
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TimeStampOfAssociatedLegacyPublishXmlFile />
<_PublishTargetUrl>D:\MonoLogueChi\Documents\GitHub\MetingJS.Server\MetingJS.Server.Fc\bin\Release\netcoreapp2.1\publish\</_PublishTargetUrl>
</PropertyGroup>
</Project>
24 changes: 24 additions & 0 deletions MetingJS.Server.Fc/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AllowedHosts": "*",
"WithOrigins": [
"*"
],
"Urls": "http://localhost:5000",
"Url": "",
"Replace": {
"Url": [
[ "http://", "https://" ],
[ "ws.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com" ]
],
"Pic": [
[ "http://", "https://" ]
]
}
}
24 changes: 24 additions & 0 deletions MetingJS.Server.Fc/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"WithOrigins": [
"*"
],
"Url": "",
"DefaultServerProvider": "Tencent",
"Replace": {
"Url": [
[ "http://", "https://" ],
[ "ws.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com" ]
],
"Pic": [
[ "http://", "https://" ]
]
}
}
14 changes: 7 additions & 7 deletions MetingJS.Server.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetingJS.Server.Fc", "MetingJS.Server.Fc\MetingJS.Server.Fc.csproj", "{9902B01C-7372-42A8-B69A-C3823761AD10}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetingJS.Server.Fc", "MetingJS.Server.Fc\MetingJS.Server.Fc.csproj", "{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -25,12 +25,12 @@ Global
{A1955290-E9A3-4572-B250-76C55F88B92D}.Linux|Any CPU.Build.0 = Linux|Any CPU
{A1955290-E9A3-4572-B250-76C55F88B92D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1955290-E9A3-4572-B250-76C55F88B92D}.Release|Any CPU.Build.0 = Release|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Linux|Any CPU.ActiveCfg = Debug|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Linux|Any CPU.Build.0 = Debug|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9902B01C-7372-42A8-B69A-C3823761AD10}.Release|Any CPU.Build.0 = Release|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Linux|Any CPU.ActiveCfg = Debug|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Linux|Any CPU.Build.0 = Debug|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{783CD8DB-2B6E-477B-A57C-F603D4ACFC64}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions MetingJS.Server/Controllers/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MusicController(Meting meting, AppSettings settings)
[HttpGet]
public ActionResult<string> Get([FromQuery] QueryModel query)
{

if (string.IsNullOrEmpty(query.Id)) return BadRequest();

var meting = query.Server.Equals(_settings.DefaultServerProvider)
Expand Down
21 changes: 18 additions & 3 deletions MetingJS.Server/MetingJS.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<Configurations>Debug;Release;Linux</Configurations>
</PropertyGroup>

Expand All @@ -15,8 +15,23 @@
<DefineConstants>TRACE;LINUX</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>NETCORE31</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<DefineConstants>NETCORE21</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Meting4Net" Version="1.1.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Meting4Net" Version="1.1.4" />
<PackageReference Include="System.Text.Json" Version="4.7.1" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
Expand Down
1 change: 1 addition & 0 deletions MetingJS.Server/MetingJS.Server.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
<ActiveDebugProfile>MetingJS.Server</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
<ActiveDebugFramework>netcoreapp2.1</ActiveDebugFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
Expand Down
78 changes: 49 additions & 29 deletions MetingJS.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
#if LINUX
using System.IO;
#endif

namespace MetingJS.Server
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().ConfigureKestrel((context, options) =>
{
#if LINUX
if (File.Exists("/tmp/metingJS.Server.sock")) File.Delete("/tmp/metingJS.Server.sock");
options.ListenUnixSocket("/tmp/metingJS.Server.sock");
#endif
});
});
}
}
#if NETCORE31
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
#elif NETCORE21
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
#endif

#if LINUX
using System.IO;
#endif

namespace MetingJS.Server
{
public class Program
{
#if NETCORE21
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
#elif NETCORE31

public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().ConfigureKestrel((context, options) =>
{
#if LINUX
if (File.Exists("/tmp/metingJS.Server.sock")) File.Delete("/tmp/metingJS.Server.sock");
options.ListenUnixSocket("/tmp/metingJS.Server.sock");
#endif
});
});
#endif
}

}

50 changes: 50 additions & 0 deletions MetingJS.Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NETCORE31
using MetingJS.Server.Models;
using MetingJS.Server.Utils;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -41,3 +42,52 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AppSetti
}
}
}

#endif

#if NETCORE21
using MetingJS.Server.Models;
using MetingJS.Server.Utils;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MetingJS.Server
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSingleton(new AppSettings(Configuration));
services.AddScoped<Meting>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, AppSettings appSettings)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseCors(builder =>
builder.WithOrigins(appSettings.WithOrigins).SetIsOriginAllowedToAllowWildcardSubdomains()
.WithMethods("GET", "OPTIONS")
.AllowAnyHeader());

app.UseMvc();
}
}
}
#endif
Loading

0 comments on commit c9bcd3b

Please sign in to comment.