Skip to content

Commit

Permalink
feat: #8 Request naver image search api
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Apr 23, 2022
1 parent 02d66f7 commit 89a0694
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"vite": "^2.9.2"
},
"dependencies": {
"axios": "^0.26.1",
"nanoid": "^3.3.1"
}
}
11 changes: 11 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
CanvasCursor,
BrushSize,
} from './lib/index.js';
import { getImage } from './api/main';
const getSearchImageLists = async (search) => {
const result = await getImage(search);
console.log(result.data.items);
};
try {
getSearchImageLists('숫자 선잇기 도안');
} catch (err) {
console.error(err);
}
</script>

<div class="world">
Expand Down
14 changes: 14 additions & 0 deletions src/api/core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios';

const { VITE_CLIENT_ID, VITE_CLIENT_SECRET } = import.meta.env;

const request = axios.create({
baseURL: '/v1',
timeout: 2500,
headers: {
'X-Naver-Client-Id': VITE_CLIENT_ID,
'X-Naver-Client-Secret': VITE_CLIENT_SECRET,
},
});

export default request;
9 changes: 9 additions & 0 deletions src/api/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import request from './core';

export const getImage = (keyword) => {
const query = encodeURI(keyword);

return request.get(`/search/image`, {
params: { query, display: 20, start: 1 },
});
};
18 changes: 14 additions & 4 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

// https://vitejs.dev/config/
export default defineConfig({
base: '',
plugins: [svelte()],
export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory
const env = loadEnv(mode, process.cwd());
console.log(env);
return {
base: '',
plugins: [svelte()],
server: {
proxy: {
'/v1': env.VITE_BASE_API,
},
},
};
});

0 comments on commit 89a0694

Please sign in to comment.