Сообщение index.cshtml в React SPA приложении. как? от 25.03.2019 13:54
Изменено 25.03.2019 13:54 VladCore
Вот цитата из react на похожую тему:
## Injecting Data from the Server into the Page
Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example:
```js
<!doctype html>
<html lang="en">
<head>
<script>
window.SERVER_DATA = __SERVER_DATA__;
</script>
```
Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**
Вопрос. Как?
По идее должно быть так:
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
// Так увы нельзя :)
spa.Options.DefaultPage = "~/index.cshtml"
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
Но увы и ах.
Даже Гугл увы не знает что такое ISpaBuilder DefaultPage. Его мегамозг предлагает поискать "ispa builder default page"
Вот цитата из react на похожую тему:
## Injecting Data from the Server into the Page
Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example:
```js
<!doctype html>
<html lang="en">
<head>
<script>
window.SERVER_DATA = __SERVER_DATA__;
</script>
```
Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**
Вопрос. Как?
По идее должно быть так:
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
// Так увы нельзя :)
spa.Options.DefaultPage = "/index.cshtml"
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
Но увы и ах.
Даже Гугл увы не знает что такое ISpaBuilder DefaultPage. Его мегамозг предлагает поискать "ispa builder default page"