配置WSGI为单个页面应用程序提供单个index.html文件 [英] Configuring WSGI to service a single index.html file for a single page application

查看:138
本文介绍了配置WSGI为单个页面应用程序提供单个index.html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Apache2(Ubuntu 18.04)上使用WSGI设置的标准Django应用程序

I have a standard Django application set up using WSGI on Apache2 (Ubuntu 18.04)

我现在想通过一个index.html文件提供所有前端内容(仍然允许访问/admin网址并确保通过/api进行REST api调用).我正在将Ember用于单页应用程序.

I now want to serve all front end content via a single index.html file (still allowing access the /admin url and ensuring the REST api calls via /api work). I'm using Ember for the single page application.

任何帮助,不胜感激!

这是我当前的.conf设置:

Here is my current .conf set up:

DocumentRoot /var/www/examplesite.co.uk/public_html

Alias /static /home/someuser/djangoprojects/someuser_v1_project/static
<Directory /home/someuser/djangoprojects/someuser_v1_project/static>
      Require all granted
</Directory>

Alias /media /home/someuser/djangoprojects/someuser_v1_project/media
<Directory /home/someuser/djangoprojects/someuser_v1_project/media>
      Require all granted
 </Directory>

 <Directory /home/someuser/djangoprojects/someuser_v1_project/someuser_v1_project>
 <Files wsgi.py>
        Require all granted
 </Files>
 </Directory>

 WSGIDaemonProcess examplesite.co.uk python-home=/home/someuser/virtualenvs/someuser_env python-path=/home/someuser/djangoprojects/someuser_v1_project
 WSGIProcessGroup examplesite.co.uk
 WSGIScriptAlias / /home/someuser/djangoprojects/someuser_v1_project/someuser_v1_project/wsgi.py

推荐答案

由于index.html将是静态的,因此只需按原样发送到用户代理(浏览器)即可.它不需要任何服务器端处理(WSGI).

Since your index.html will be static it just needs to be sent to the user-agent (browser) as is. It doesn't need any server-side processing (WSGI).

Web服务器可以根据浏览器的请求简单地发送index.html(和任何js/css资源).它甚至不需要与API后端位于同一目录中.

The web-server can simply send index.html (and any js/css resources) as requested by the browser. It doesn't even need to be in the same directory as your API back-end.

我在生产应用中使用了这样的设置.这样可以使开发和部署独立于前端/后端.

I am using a set-up like this in a production app. This keeps development and deployment independent for front/back.

/www
  /myapp                <-- ember SPA (where normal users will go)
     index.html
    /assets
    /fonts
  /myapp_backend
    /api/v1/...          <-- backend API (API that ember talks to)
    /admin/              <-- admin section

您可以在ember config生产设置中定义后端API位置. (在开发中可能是不同的设置).然后,您可以将余烬应用程序数据适配器中的名称空间设置为此路径.

You can define the backend API location in ember config production settings. (Could be different settings in development). You can then set the namespace in your ember application data adapter to this path.

// config/environment.js
...
APP: {
  ENV: {
         REST_API_ENDPOINT: 'myapp_backend/api/v1',
         REST_API_HOST:     'http://production-host',
       ...
       }

  ...
}

// app/adapters/application.js
import DS from 'ember-data';
import ENV from '../config/environment';
...

export default DS.RESTAdapter.extend({
    namespace: ENV.APP.REST_API_ENDPOINT,
    host:      ENV.APP.REST_API_HOST,
    ...
})

发布就绪后,您可以ember build --environment=production并将"dist"目录复制到服务器myapp目录.

When a release is ready you can ember build --environment=production and copy 'dist' directory to the server myapp directory.

这篇关于配置WSGI为单个页面应用程序提供单个index.html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆