1+ using Jering . Javascript . NodeJS ;
2+ using Microsoft . AspNetCore . Mvc ;
3+
4+ using JavaScriptEngineSwitcher . ChakraCore ;
5+ using JavaScriptEngineSwitcher . Extensions . MsDependencyInjection ;
6+ using JavaScriptEngineSwitcher . Jint ;
7+ using JavaScriptEngineSwitcher . Jurassic ;
8+ using JavaScriptEngineSwitcher . Msie ;
9+ using JavaScriptEngineSwitcher . NiL ;
10+ using JavaScriptEngineSwitcher . Node ;
11+ using JavaScriptEngineSwitcher . Sample . Logic . Services ;
12+ using JavaScriptEngineSwitcher . V8 ;
13+ using JavaScriptEngineSwitcher . Vroom ;
14+ using JavaScriptEngineSwitcher . Yantra ;
15+
16+ var builder = WebApplication . CreateBuilder ( new WebApplicationOptions ( ) {
17+ WebRootPath = Path . Combine (
18+ Directory . GetCurrentDirectory ( ) ,
19+ "../JavaScriptEngineSwitcher.Sample.AspNetCore.ClientSideAssets/wwwroot"
20+ )
21+ } ) ;
22+ var env = builder . Environment ;
23+ var configuration = new ConfigurationBuilder ( )
24+ . SetBasePath ( env . ContentRootPath )
25+ . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
26+ . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true )
27+ . AddEnvironmentVariables ( )
28+ . Build ( )
29+ ;
30+
31+ #region Configure services
32+
33+ IServiceCollection services = builder . Services ;
34+
35+ services . AddSingleton ( configuration ) ;
36+
37+ // Add Jering Node.js service to the services container.
38+ services . AddNodeJS ( ) ;
39+
40+ // Add JavaScriptEngineSwitcher services to the services container.
41+ services . AddJsEngineSwitcher ( options =>
42+ {
43+ options . AllowCurrentProperty = false ;
44+ options . DefaultEngineName = ChakraCoreJsEngine . EngineName ;
45+ } )
46+ . AddChakraCore ( )
47+ . AddJint ( )
48+ . AddJurassic ( )
49+ . AddMsie ( options =>
50+ {
51+ options . EngineMode = JsEngineMode . ChakraIeJsRt ;
52+ } )
53+ . AddNiL ( )
54+ . AddNode ( services )
55+ . AddV8 ( )
56+ . AddVroom ( )
57+ . AddYantra ( )
58+ ;
59+
60+ services . Configure < MvcOptions > ( options =>
61+ {
62+ options . CacheProfiles . Add ( "CacheCompressedContent5Minutes" ,
63+ new CacheProfile
64+ {
65+ NoStore = builder . Environment . IsDevelopment ( ) ,
66+ Duration = 300 ,
67+ Location = ResponseCacheLocation . Client ,
68+ VaryByHeader = "Accept-Encoding"
69+ }
70+ ) ;
71+ } ) ;
72+
73+ // Add framework services.
74+ services . AddControllersWithViews ( ) ;
75+
76+ // Add JavaScriptEngineSwitcher sample services to the services container.
77+ services . AddSingleton < JsEvaluationService > ( ) ;
78+
79+ #endregion
80+
81+ #region Configure the HTTP request pipeline
82+
83+ var app = builder . Build ( ) ;
84+
85+ if ( app . Environment . IsDevelopment ( ) )
86+ {
87+ app . UseDeveloperExceptionPage ( ) ;
88+ }
89+ else
90+ {
91+ app . UseExceptionHandler ( "/Home/Error" ) ;
92+ }
93+
94+ app . UseRouting ( ) ;
95+
96+ app . MapStaticAssets ( ) ;
97+
98+ app . MapControllerRoute (
99+ name : "default" ,
100+ pattern : "{controller=Home}/{action=Index}/{id?}" )
101+ . WithStaticAssets ( ) ;
102+
103+ #endregion
104+
105+ app . Run ( ) ;
0 commit comments