mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 02:16:03 +00:00
Dynamic API url
This commit is contained in:
parent
36d6b9ff7a
commit
19244cfbfb
@ -16,7 +16,7 @@ module.exports = {
|
||||
const settings = _.pick(strapi.config, [
|
||||
'name',
|
||||
'version',
|
||||
'description'
|
||||
'description'
|
||||
]);
|
||||
|
||||
this.body = settings;
|
||||
@ -26,9 +26,10 @@ module.exports = {
|
||||
var data = this.request.body;
|
||||
|
||||
try {
|
||||
const settingsUpdated = yield strapi.plugins.settingsmanager.services.settingsservice.configurationsManager(strapi, data);
|
||||
const settingsUpdated = yield strapi.plugins['settings-manager'].services.settingsservice.configurationsManager(strapi, data);
|
||||
this.body = settingsUpdated.values;
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
this.status = err && err.status || 400;
|
||||
return this.body = {
|
||||
message: err.msg || 'An error occurred during settings update'
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* app.js
|
||||
*
|
||||
* This is the entry file for the application, only setup and plugin
|
||||
* code.
|
||||
* This is the entry file for the application,
|
||||
* only setup and plugin code.
|
||||
*/
|
||||
|
||||
import { browserHistory } from 'react-router';
|
||||
@ -19,11 +19,14 @@ const store = configureStore(initialState, browserHistory);
|
||||
import App from 'containers/App';
|
||||
import createRoutes from './routes';
|
||||
|
||||
// Plugin identifier based on the package.json `name` value
|
||||
const pluginId = require('../package.json').name.replace(/^strapi-/i, '');
|
||||
|
||||
// Register the plugin
|
||||
if (window.Strapi) {
|
||||
window.Strapi.registerPlugin({
|
||||
name: 'Settings Manager',
|
||||
id: 'settings-manager',
|
||||
id: pluginId,
|
||||
leftMenuLink: {
|
||||
label: 'Settings Manager',
|
||||
to: '/settings-manager',
|
||||
@ -33,7 +36,11 @@ if (window.Strapi) {
|
||||
});
|
||||
}
|
||||
|
||||
// API
|
||||
const apiUrl = `${window.Strapi.apiUrl}/${pluginId}`;
|
||||
|
||||
// Export store
|
||||
export {
|
||||
store,
|
||||
};
|
||||
apiUrl,
|
||||
};
|
||||
|
||||
@ -37,7 +37,6 @@ class LeftMenu extends React.Component { // eslint-disable-line react/prefer-sta
|
||||
}];
|
||||
|
||||
render() {
|
||||
|
||||
const linksElements = this.links.map((link, i) => (<LeftMenuLink key={i} link={link}></LeftMenuLink>));
|
||||
|
||||
return (
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
import { fromJS } from 'immutable';
|
||||
import expect from 'expect';
|
||||
|
||||
import { selectLocationState } from 'containers/App/selectors';
|
||||
|
||||
describe('selectLocationState', () => {
|
||||
it('should select the route as a plain JS object', () => {
|
||||
const route = fromJS({
|
||||
locationBeforeTransitions: null,
|
||||
});
|
||||
const mockedState = fromJS({
|
||||
route,
|
||||
});
|
||||
expect(selectLocationState()(mockedState)).toEqual(route.toJS());
|
||||
});
|
||||
});
|
||||
@ -20,12 +20,13 @@ import {
|
||||
selectDescription,
|
||||
selectVersion,
|
||||
} from 'containers/HomePage/selectors';
|
||||
import { apiUrl } from '../../app';
|
||||
|
||||
/**
|
||||
* General Settings request/response handler
|
||||
*/
|
||||
export function* getGeneralSettings() {
|
||||
const requestURL = 'http://localhost:1337/settingsmanager/settings/general';
|
||||
const requestURL = `${apiUrl}/settings/general`;
|
||||
|
||||
// Call our request helper (see 'utils/request')
|
||||
const generalSettings = yield call(request, requestURL);
|
||||
@ -50,7 +51,7 @@ export function* updateGeneralSettings() {
|
||||
type: 'general',
|
||||
};
|
||||
|
||||
const requestURL = 'http://localhost:1337/settingsmanager/settings';
|
||||
const requestURL = `${apiUrl}/settings`;
|
||||
|
||||
// Call our request helper (see 'utils/request')
|
||||
const generalSettings = yield call(
|
||||
|
||||
@ -8,7 +8,6 @@ const fs = require('fs');
|
||||
const componentGenerator = require('./component/index.js');
|
||||
const containerGenerator = require('./container/index.js');
|
||||
const routeGenerator = require('./route/index.js');
|
||||
const languageGenerator = require('./language/index.js');
|
||||
|
||||
module.exports = (plop) => {
|
||||
plop.setGenerator('component', componentGenerator);
|
||||
|
||||
@ -6,7 +6,6 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const webpack = require('webpack');
|
||||
const logger = require('../../server/logger');
|
||||
const cheerio = require('cheerio');
|
||||
const pkg = require(path.resolve(process.cwd(), 'package.json'));
|
||||
const dllPlugin = pkg.dllPlugin;
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
|
||||
@ -5,15 +5,9 @@ const logger = require('./logger');
|
||||
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
const setup = require('./middlewares/frontendMiddleware');
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
const ngrok = (isDev && process.env.ENABLE_TUNNEL) || argv.tunnel ? require('ngrok') : false;
|
||||
const resolve = require('path').resolve;
|
||||
const app = express();
|
||||
|
||||
// If you need a backend, e.g. an API, add your custom backend-specific middleware here
|
||||
// app.use('/api', myApi);
|
||||
|
||||
// In production we need to pass these values in instead of relying on webpack
|
||||
setup(app, {
|
||||
outputPath: resolve(process.cwd(), 'build'),
|
||||
publicPath: '/',
|
||||
@ -27,17 +21,4 @@ app.listen(port, (err) => {
|
||||
if (err) {
|
||||
return logger.error(err.message);
|
||||
}
|
||||
|
||||
// Connect to ngrok in dev mode
|
||||
if (ngrok) {
|
||||
ngrok.connect(port, (innerErr, url) => {
|
||||
if (innerErr) {
|
||||
return logger.error(innerErr);
|
||||
}
|
||||
|
||||
logger.appStarted(port, url);
|
||||
});
|
||||
} else {
|
||||
logger.appStarted(port);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
/* eslint-disable global-require */
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const compression = require('compression');
|
||||
const pkg = require(path.resolve(process.cwd(), 'package.json'));
|
||||
|
||||
// Dev middleware
|
||||
@ -42,32 +40,12 @@ const addDevMiddlewares = (app, webpackConfig) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Production middlewares
|
||||
const addProdMiddlewares = (app, options) => {
|
||||
const publicPath = options.publicPath || '/';
|
||||
const outputPath = options.outputPath || path.resolve(process.cwd(), 'build');
|
||||
|
||||
// compression middleware compresses your server responses which makes them
|
||||
// smaller (applies also to assets). You can read more about that technique
|
||||
// and other good practices on official Express.js docs http://mxs.is/googmy
|
||||
app.use(compression());
|
||||
app.use(publicPath, express.static(outputPath));
|
||||
|
||||
app.get('*', (req, res) => res.sendFile(path.resolve(outputPath, 'index.html')));
|
||||
};
|
||||
|
||||
/**
|
||||
* Front-end middleware
|
||||
*/
|
||||
module.exports = (app, options) => {
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
if (isProd) {
|
||||
addProdMiddlewares(app, options);
|
||||
} else {
|
||||
const webpackConfig = require('../../internals/webpack/webpack.dev.babel');
|
||||
addDevMiddlewares(app, webpackConfig);
|
||||
}
|
||||
module.exports = (app) => {
|
||||
const webpackConfig = require('../../internals/webpack/webpack.dev.babel');
|
||||
addDevMiddlewares(app, webpackConfig);
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user