Я пытаюсь развернуть Django -React to elasti c beanstalk, развертывание отображается как успешное, но дает мне только белую пустую страницу (вызовы API работают правильно).
Inspecting / var /log/nginx/error.log показывает:
2020/08/06 02:58:06 [error] 4461#0: *11 open() "/var/app/current/staticbundle.js" failed (2: No such file or directory)
Итак, я понимаю, что он пытается найти пакет. js, но на неправильном пути, который я не знаю, как исправить, и должен выглядеть так :
/var/app/current/static/bundle.js
Я думал, что он неправильно строит папку stati c, но это так, и в итоге все закончилось так:
current
│
└───static
│ │ bundle.js
│ │ index.html
│
└───...
это настройки моего проекта
- Django сторона:
1,1 settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
1,2 urls.py
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.generic import TemplateView
urlpatterns = [
path('api/', include('backend.urls')),
re_path(r'^.*', TemplateView.as_view(template_name='index.html')),
]
1,3 django .config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: cerbero.wsgi
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static/: static/
container_commands:
01_node_install:
command: "curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash - && sudo yum -y install nodejs"
ignoreErrors: false
02_npm_install:
command: "npm install"
ignoreErrors: false
03_react_collect:
command: "npm run build"
ignoreErrors: false
2.Сторона WebPack: - webpack.config. js
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './frontend/src/index.js',
watch : false,
devtool : 'source-map',
output : {
filename: 'bundle.js',
path : path.resolve(__dirname, 'static/'),
publicPath: '/',
},
devServer: {
contentBase: './',
inline: true,
hot: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './frontend/templates/frontend/index.html',
filename : './index.html',
minify: false
})
]
};
<!doctype html>
{%load static %}
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cerbero</title>
</head>
<body>
<div id="app"></div>
<script src = "{% static '/bundle.js' %}"></script>
</body>
</html>
Я действительно не могу сказать, связана ли проблема с django, веб-пакетом или реакцией