我有一个项目,需要为我的PWA(ReactJS)创建一个动态的manifest.json文件。
请查看下面的代码:
我对这种事情还很陌生。我该如何开始?
请查看下面的代码:
app.service.js:
function getAppDetails() {
const requestOptions = {
method: 'GET',
headers: authHeader()
};
// TODO create dynamic manifest.json file here
return fetch(`${config.apiUrl}/api/apps`, requestOptions).then(handleResponse);
}
function handleResponse(response) {
return response.text().then(text => {
const data = text && JSON.parse(text);
if (!response.ok) {
if (response.status === 401) {
// auto logout if 401 response returned from api
logout();
location.reload(true);
}
const error = (data && data.message) || response.statusText;
return Promise.reject(error);
}
return data;
});
}
app.actions.js:
function getAppDetails() {
return dispatch => {
dispatch(request());
appService.getAppDetails()
.then(
details => dispatch(success(details)),
error => dispatch(failure(error.toString()))
);
};
function request() { return { type: appConstants.GETDETAILS_REQUEST } }
function success(details) { return { type: appConstants.GETDETAILS_SUCCESS, details } }
function failure(error) { return { type: appConstants.GETDETAILS_FAILURE, error } }
}
LoginPage.jsx:
import { appActions } from '../_actions';
class LoginPage extends React.Component {
constructor(props) {
super(props);
// reset login status
this.props.dispatch(userActions.logout());
this.state = {
email: '',
password: '',
isDisabled: false,
submitted: false
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.showSwal = this.showSwal.bind(this);
}
componentDidMount() {
// TODO call the action to add dynamic manifest file to index.html
this.props.dispatch(aapActions.getAppDetails());
}
render() {
return (
................
);
}
}
我对这种事情还很陌生。我该如何开始?