Skip to content

Commit

Permalink
Merge pull request #2 from danmooozi/develop
Browse files Browse the repository at this point in the history
기본작업 추가
  • Loading branch information
gitdog01 authored Dec 23, 2023
2 parents 687472a + 3cd7e47 commit d5781d5
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SERVER_PORT=
CLIENT_ID=
CLIENT_SECRET=
6 changes: 6 additions & 0 deletions .prttierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trailingComma: "es5"
tabWidth: 2
semi: true
singleQuote: true
trailingComma: "all"
printWidth: 80
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@types/axios": "^0.14.0",
"axios": "^1.6.2",
"express": "^4.18.2",
"prettier": "^3.1.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0"
}
Expand Down
1 change: 1 addition & 0 deletions src/app.middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const swaggerSpec = swaggerJSDoc(swaggerJsdocOptions);

export default (app: express.Application) => {
app.use(express.urlencoded({ extended: false }));
app.use(express.static(__dirname + '/public'));
app.use('/api', router);
app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
};
19 changes: 19 additions & 0 deletions src/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<body>
<button type="button" id="github-button">github-button</button>
</body>

<script>
const button = document.querySelector('#github-button');
button.addEventListener('click', (e) => {
e.preventDefault();
const scope = 'public_repo';
const redirect_uri = 'http://localhost:3000/api/v1/callback';
const client_id = '992209430f73ccf5eaf1';

const url = `https://github.com/login/oauth/authorize?scope=${scope}&redirect_uri=${redirect_uri}&client_id=${client_id}`;
console.log(url);
window.location.href = url;
});
</script>
</html>
6 changes: 4 additions & 2 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import express from 'express';
import testRouter from './test';
import v1Router from './v1';
import v2Router from './v2';

const router = express.Router();

router.use('/test', testRouter);
router.use('/v1', v1Router);
router.use('/v2', v2Router);

export default router;
10 changes: 0 additions & 10 deletions src/routes/test/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/routes/test/v1/index.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/routes/test/v1/test.swagger.js

This file was deleted.

56 changes: 56 additions & 0 deletions src/routes/v1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import express from 'express';
import axios from 'axios';

const router = express.Router();

router.get('/callback', async (req, res) => {
const { code } = req.query;

const result = await axios({
method: 'post',
url: `https://github.com/login/oauth/access_token`,
headers: {
accept: 'application/json',
},
data: {
client_id: Bun.env.CLIENT_ID,
client_secret: Bun.env.CLIENT_SECRET,
code,
},
});
console.log(result.data);
if (result.data.error) {
console.log(result.data.error);
res.json(false);
return;
}
res.json(true);
});

router.get('data', async (req, res) => {
const starCount = 55; // number
const followerCount = 123; // number
const followingCount = 223; // number
const mostUsedLanguage = ['JavaScript', 'TypeScript', 'Python']; // string[]
const moreThan = 'high'; // high, middle, low
const commitCount = 1234; // number
const commitDate = '월요일'; // 월요일, 화요일, 수요일, 목요일, 금요일, 토요일, 일요일
const mostCommunication = {
// 여기 줄때 github profile 주소도 주면 좋지 않을까 ?
name: 'bsy1141', // string
image: 'https://avatars.githubusercontent.com/u/60652298?v=4', // string
};

res.json({
starCount,
followerCount,
followingCount,
mostUsedLanguage,
moreThan,
commitCount,
commitDate,
mostCommunication,
});
});

export default router;
9 changes: 9 additions & 0 deletions src/routes/v1/test.swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @swagger
* tags:
* - name: test
* description: test api doc
* @swagger
* /api/v1/callback:
* get:
*/
1 change: 0 additions & 1 deletion src/routes/test/v2/index.ts → src/routes/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import express from 'express';

const router = express.Router();
Expand Down
File renamed without changes.

0 comments on commit d5781d5

Please sign in to comment.