Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions client/src/api/models/gh-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Octokit } from 'octokit';
import { AuthError } from '../errors';

import { accessToken } from '~/configs/server';
import { Octokit } from '../models/services/octokit';

export async function GhUser() {
const octokit = new Octokit({ auth: accessToken });
const octokit = Octokit();

try {
const { data } = await octokit.request('GET /user');
Expand Down
9 changes: 9 additions & 0 deletions client/src/api/models/services/octokit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Octokit as InternalOctokit } from 'octokit';
import { accessToken, customFetch } from '~/configs/server';

export function Octokit() {
return new InternalOctokit({
auth: accessToken,
fetch: customFetch
})
}
5 changes: 4 additions & 1 deletion client/src/configs/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type Server = {
saAccessKey: string;
saPrivateKey: string;
saResourceId: string;
fetch?: typeof global.fetch;
};

const state = config<Server>('server');
Expand All @@ -28,4 +29,6 @@ export const saAccessKey = state.saAccessKey;

export const saPrivateKey = state.saPrivateKey;

export const saResourceId = state.saResourceId;
export const saResourceId = state.saResourceId;

export const fetch = state.fetch || global.fetch;
6 changes: 5 additions & 1 deletion server/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const {

const app = express();

app.use(quickstart({navigation, base: 'http://localhost:3001/'}));
app.use(quickstart({
navigation,
base: 'http://localhost:3001/',
fetch: gozoraFetch
}));

app.listen(PORT, () => {
console.log('LISTEN ON ', PORT);
Expand Down
4 changes: 2 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const nodekit = new NodeKit({

const DEFAULT_URLS = { api: '/api', auth: '/auth' };

export const router = ({navigation, urls = {}, base = '/static'} = {}) => {
export const router = ({navigation, urls = {}, base = '/static', fetch} = {}) => {
urls = {...DEFAULT_URLS, urls};

const router = new Router();
Expand All @@ -38,7 +38,7 @@ export const router = ({navigation, urls = {}, base = '/static'} = {}) => {
next();
});

router.get('/', root({urls, navigation, base}));
router.get('/', root({urls, navigation, base, fetch}));
router.use(urls.api || '/api', api(router));
router.use(urls.auth || '/auth', auth(router));

Expand Down
4 changes: 2 additions & 2 deletions server/routes/root/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import manifest from '@diplodoc/cabinet/manifest';

import config from '../../utils/config.js';

export const router = ({navigation, urls, base}) => {
export const router = ({navigation, urls, base, fetch}) => {
const router = new Router();

router.get('/', async (req, res) => {
const bootstrap = manifest(base || '/static');

const state = {
...config(req),
...config(req, fetch),
manifest: bootstrap,
urls,
navigation
Expand Down
3 changes: 2 additions & 1 deletion server/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ENV = {
saResourceId: envconfig.expectEnv('FOLDER_ID')('b1g1j115gl75k4sqiu0m')
};

export default (req) => ({
export default (req, fetch) => ({
api: {
request: req.ctx.request.bind(req.ctx)
},
Expand All @@ -19,5 +19,6 @@ export default (req) => ({
server: {
...req.session,
...ENV,
fetch
}
});