mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
feat(build): Add buildPath to config.
This commit is contained in:
parent
d5db970b55
commit
1cce024339
@ -39,6 +39,11 @@ async function validateConfig({ components }) {
|
||||
if (type.isNone(components.config.theme)) {
|
||||
components.config.theme = {};
|
||||
}
|
||||
if (type.isString(components.config.basePath)) {
|
||||
if (components.config.basePath[0] !== '/') {
|
||||
throw Error('Base path must start with "/".');
|
||||
}
|
||||
}
|
||||
validate({
|
||||
schema: lowdefySchema.definitions.authConfig,
|
||||
data: components.config.auth,
|
||||
|
@ -155,3 +155,31 @@ test('validateConfig config error when protected or public are false.', async ()
|
||||
'Public pages can not be set to false.'
|
||||
);
|
||||
});
|
||||
|
||||
test('validateConfig config error when basePath does not start with "/".', async () => {
|
||||
let components = {
|
||||
config: {
|
||||
basePath: '/base',
|
||||
},
|
||||
};
|
||||
const result = await validateConfig({ components, context });
|
||||
expect(result).toEqual({
|
||||
config: {
|
||||
auth: {
|
||||
pages: {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
basePath: '/base',
|
||||
theme: {},
|
||||
},
|
||||
});
|
||||
components = {
|
||||
config: {
|
||||
basePath: 'base',
|
||||
},
|
||||
};
|
||||
await expect(validateConfig({ components, context })).rejects.toThrow(
|
||||
'Base path must start with "/".'
|
||||
);
|
||||
});
|
||||
|
@ -598,6 +598,13 @@ export default {
|
||||
auth: {
|
||||
$ref: '#/definitions/authConfig',
|
||||
},
|
||||
basePath: {
|
||||
type: 'string',
|
||||
description: 'App base path to apply to all routes. Base path must start with "/".',
|
||||
errorMessage: {
|
||||
type: 'App "config.basePath" should be a string.',
|
||||
},
|
||||
},
|
||||
homePageId: {
|
||||
type: 'string',
|
||||
description:
|
||||
|
@ -42,6 +42,7 @@ _ref:
|
||||
|
||||
The config object has the following properties:
|
||||
|
||||
- `basePath: string`: Set the base path to serve the Lowdefy application from. This will route all pages under `https://example.com/<base-path>/<page-id>` instead of the default `https://example.com/<page-id>`. The basePath value must start with "/".
|
||||
- `homePageId: string`: The pageId of the page that should be loaded when a user loads the app without a pageId in the url route. This is the page that is loaded when you navigate to `yourdomain.com`.
|
||||
- `experimental_initPageId: string`: The pageId of the page that should be loaded when app is initialized. User is then redirected to requeted page. You can use onInit/onInitAsync/onEnter/onEnterAsync events to fetch and prepare global variables for other parts of the app.
|
||||
|
||||
|
@ -32,7 +32,7 @@ _ref:
|
||||
|
||||
The Lowdefy server can be configured using the following environment variables:
|
||||
|
||||
- `LOWDEFY_SERVER_BASE_PATH`: Set the base path to serve the Lowdefy application from. This will serve the application under `https://example.com/<base-path>`instead of `https://example.com`, and all pages under `https://example.com/<base-path>/<page-id>` instead of the default `https://example.com/<page-id>`.
|
||||
- `LOWDEFY_BASE_PATH`: Set the base path to serve the Lowdefy application from. This will serve the application under `https://example.com/<base-path>`instead of `https://example.com`, and all pages under `https://example.com/<base-path>/<page-id>` instead of the default `https://example.com/<page-id>`.
|
||||
- `LOWDEFY_SERVER_BUILD_DIRECTORY`: The directory of the built Lowdefy configuration (The output of `lowdefy build`, usually found at `./.lowdefy/build` in your project repository). The default is `./build` (or `/home/node/lowdefy/build`).
|
||||
- `LOWDEFY_SERVER_PUBLIC_DIRECTORY`: The directory of the public assets to be served. The default is `./public` (or `/home/node/lowdefy/public`).
|
||||
- `LOWDEFY_SERVER_PORT`: The port (inside the container) at which to run the server. The default is `3000`.
|
||||
|
@ -105,7 +105,7 @@ _ref:
|
||||
|
||||
The following environment variables can be specified:
|
||||
|
||||
- `LOWDEFY_SERVER_BASE_PATH`: Set the base path to serve the Lowdefy application from. This will serve the application under `https://example.com/<base-path>`instead of `https://example.com`, and all pages under `https://example.com/<base-path>/<page-id>` instead of the default `https://example.com/<page-id>`.
|
||||
- `LOWDEFY_BASE_PATH`: Set the base path to serve the Lowdefy application from. This will serve the application under `https://example.com/<base-path>`instead of `https://example.com`, and all pages under `https://example.com/<base-path>/<page-id>` instead of the default `https://example.com/<page-id>`.
|
||||
- `LOWDEFY_SERVER_BUILD_DIRECTORY`: The directory of the built Lowdefy configuration (The output of `lowdefy build`, usually found at `./.lowdefy/build` in your project repository). The default is `./.lowdefy/build`.
|
||||
- `LOWDEFY_SERVER_PORT`: The port at which to run the server. The default is `3000`.
|
||||
- `LOWDEFY_SERVER_PUBLIC_DIRECTORY`: The directory of the public assets to be served. The default is `./public`.
|
||||
|
@ -7,6 +7,7 @@ module.exports = withLess({
|
||||
modifyVars: lowdefyConfig.theme.lessVariables,
|
||||
},
|
||||
},
|
||||
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
|
||||
// reactStrictMode: true,
|
||||
webpack: (config, { isServer }) => {
|
||||
if (!isServer) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
const withLess = require('next-with-less');
|
||||
const lowdefyConfig = require('./build/config.json');
|
||||
|
||||
// TODO: Trance env and args from cli that is required on the server.
|
||||
module.exports = withLess({
|
||||
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
|
||||
lessLoaderOptions: {
|
||||
lessOptions: {
|
||||
modifyVars: lowdefyConfig.theme.lessVariables,
|
||||
|
@ -25,6 +25,7 @@ const LowdefyContext = ({ children, lowdefy }) => {
|
||||
lowdefy._internal = {
|
||||
blockComponents,
|
||||
callRequest,
|
||||
components: {},
|
||||
document,
|
||||
operators,
|
||||
updaters: {},
|
||||
|
@ -32,10 +32,13 @@ const Page = ({ lowdefy, pageConfig, rootConfig }) => {
|
||||
lowdefy._internal.router = router;
|
||||
lowdefy._internal.link = setupLink(lowdefy);
|
||||
lowdefy._internal.components = createComponents(lowdefy);
|
||||
|
||||
lowdefy.basePath = lowdefy._internal.router.basePath;
|
||||
lowdefy.home = rootConfig.home;
|
||||
lowdefy.lowdefyGlobal = rootConfig.lowdefyGlobal;
|
||||
lowdefy.menus = rootConfig.menus;
|
||||
lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
|
||||
|
||||
return (
|
||||
<Context config={pageConfig} lowdefy={lowdefy}>
|
||||
{(context, loading) => {
|
||||
|
@ -64,12 +64,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
||||
setValue: block.setValue,
|
||||
triggerEvent: block.triggerEvent,
|
||||
})}
|
||||
// TODO: React throws a basePath warning
|
||||
basePath={lowdefy._internal.basePath}
|
||||
basePath={lowdefy.basePath}
|
||||
blockId={block.blockId}
|
||||
components={lowdefy._internal.components}
|
||||
events={block.eval.events}
|
||||
homePageId={lowdefy.home.pageId}
|
||||
key={block.blockId}
|
||||
loading={block.loading}
|
||||
menus={lowdefy.menus}
|
||||
@ -98,11 +96,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
||||
registerMethod: block.registerMethod,
|
||||
triggerEvent: block.triggerEvent,
|
||||
})}
|
||||
basePath={lowdefy._internal.basePath}
|
||||
basePath={lowdefy.basePath}
|
||||
blockId={block.blockId}
|
||||
components={lowdefy._internal.components}
|
||||
events={block.eval.events}
|
||||
homePageId={lowdefy.home.pageId}
|
||||
key={block.blockId}
|
||||
loading={block.loading}
|
||||
menus={lowdefy.menus}
|
||||
|
@ -65,12 +65,11 @@ const Container = ({ block, Blocks, Component, context, lowdefy }) => {
|
||||
registerMethod: block.registerMethod,
|
||||
triggerEvent: block.triggerEvent,
|
||||
})}
|
||||
basePath={lowdefy._internal.basePath}
|
||||
basePath={lowdefy.basePath}
|
||||
blockId={block.blockId}
|
||||
components={lowdefy._internal.components}
|
||||
content={content}
|
||||
events={block.eval.events}
|
||||
homePageId={lowdefy.home.pageId}
|
||||
key={block.blockId}
|
||||
loading={block.loading}
|
||||
menus={lowdefy.menus}
|
||||
|
@ -72,11 +72,10 @@ const List = ({ block, Blocks, Component, context, lowdefy }) => {
|
||||
triggerEvent: block.triggerEvent,
|
||||
unshiftItem: block.unshiftItem,
|
||||
})}
|
||||
basePath={lowdefy._internal.basePath}
|
||||
basePath={lowdefy.basePath}
|
||||
blockId={block.blockId}
|
||||
components={lowdefy._internal.components}
|
||||
events={block.eval.events}
|
||||
homePageId={lowdefy.home.pageId}
|
||||
key={block.blockId}
|
||||
list={contentList}
|
||||
loading={block.loading}
|
||||
|
@ -19,6 +19,7 @@ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
||||
import Page from '../components/Page.js';
|
||||
|
||||
export async function getServerSideProps() {
|
||||
// TODO: is this build directory configurable from the cli?
|
||||
const apiContext = await createApiContext({ buildDirectory: './build' });
|
||||
const rootConfig = await getRootConfig(apiContext);
|
||||
const { home } = rootConfig;
|
||||
|
@ -30,7 +30,6 @@ const lowdefyProps = [
|
||||
'components',
|
||||
'content',
|
||||
'eventLog',
|
||||
'homePageId',
|
||||
'list',
|
||||
'loading',
|
||||
'menus',
|
||||
|
@ -20,7 +20,7 @@ function getConfigFromEnv() {
|
||||
logLevel: process.env.LOWDEFY_SERVER_LOG_LEVEL,
|
||||
publicDirectory: process.env.LOWDEFY_SERVER_PUBLIC_DIRECTORY,
|
||||
port: process.env.LOWDEFY_SERVER_PORT && parseInt(process.env.LOWDEFY_SERVER_PORT),
|
||||
serverBasePath: process.env.LOWDEFY_SERVER_BASE_PATH,
|
||||
basePath: process.env.LOWDEFY_BASE_PATH,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ test('Get config from env', () => {
|
||||
buildDirectory: 'build',
|
||||
publicDirectory: 'public',
|
||||
port: 8080,
|
||||
serverBasePath: 'base',
|
||||
basePath: 'base',
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user