Skip to content

Commit

Permalink
feat: (#533) separating server and client exports, dynamically import…
Browse files Browse the repository at this point in the history
…ing server code where necessary
  • Loading branch information
wjohnsto committed Oct 5, 2021
1 parent 6fc614e commit 50638f6
Show file tree
Hide file tree
Showing 18 changed files with 420 additions and 444 deletions.
6 changes: 4 additions & 2 deletions .changeset/tough-glasses-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ With the introduction of `apiRouter` we have introduced a breaking change. You w

```ts
import 'faust.config';
import { apiRouter } from '@faustjs/core';
import { apiRouter } from '@faustjs/core/api';

export default apiRouter;
```

**Note**: The `[[...route]]` naming convention is a [Next.js convention for a catch-all route.](https://nextjs.org/docs/routing/dynamic-routes#optional-catch-all-routes)

In addition, the `apiEndpoint` config option has been removed in exchange for the `apiBasePath` option. This option specifies the base path for all of the Faust.js endpoints.
### Config changes

The `apiEndpoint` and `apiUrl` config options have been removed in exchange for the `apiBasePath` option. This option specifies the base path for all of the Faust.js endpoints. The `blogUrlPrefix` is no longer necessary and has been removed from the config interface.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'faust.config';
import { apiRouter } from '@faustjs/core';
import { apiRouter } from '@faustjs/core/api';

export default apiRouter;
1 change: 1 addition & 0 deletions packages/core/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/cjs/api';
4 changes: 4 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
},
"./api": {
"import": "./dist/mjs/api.js",
"require": "./dist/cjs/api.js"
}
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './server';
2 changes: 0 additions & 2 deletions packages/core/src/api/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './server/cookie';
export { authorizeHandler, logoutHandler } from './server/middleware';
export * from './authorize';
export * from './client/accessToken';
27 changes: 1 addition & 26 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import defaults from 'lodash/defaults';
import trimEnd from 'lodash/trimEnd';
import extend from 'lodash/extend';
import isObject from 'lodash/isObject';
import type { RequestContext } from '../api';
import type { RequestContext } from '../gqty';
import isNil from 'lodash/isNil';
import trim from 'lodash/trim';
import { isValidUrl } from '../utils';
Expand Down Expand Up @@ -51,31 +51,6 @@ export interface HeadlessConfig {
*/
apiBasePath?: string;

/**
* Set this value to the URL of your api that you want to use for this application.
*
* @example api.mysite.com
*
* @default wpUrl
* @type {string}
* @memberof HeadlessConfig
*
* @deprecated use apiBasePath instead
*/
apiUrl?: string;

/**
* This is a prefix URL path that we will use as the base URL for your WordPress posts.
* By default we will assume that your site is configured with no blog-specific URL.
*
* @example /blog
*
* @default ''
* @type {string}
* @memberof HeadlessConfig
*/
blogUrlPrefix?: string;

/**
* Set this value to be the path to your API endpoint that you want to use for this application
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import isFunction from 'lodash/isFunction';
import isNil from 'lodash/isNil';
import isObject from 'lodash/isObject';
import omit from 'lodash/omit';
import { Cookies, getAccessToken } from '../../auth';
import { OAuth } from '../../auth/server/token';
import { getGqlUrl } from '../../config/config';
import { getAccessToken } from '../auth';
import { getGqlUrl } from '../config/config';

export interface GqlClientSchema {
query: any;
Expand Down Expand Up @@ -72,6 +71,8 @@ export function createAuthQueryFetcher(
let token: string | undefined;

if (!isNil(context)) {
const { Cookies } = await import('../server/auth/cookie');
const { OAuth } = await import('../server/auth/token');
const oauth = new OAuth(new Cookies(context));
const oauthTokens = await oauth.fetch();

Expand Down
Loading

0 comments on commit 50638f6

Please sign in to comment.