Skip to content

Commit 522d9a4

Browse files
Add Next.js example
1 parent c8057e6 commit 522d9a4

17 files changed

Lines changed: 418 additions & 0 deletions

examples/nextjs/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SOLAPI_API_KEY=YOUR_API_KEY_HERE
2+
SOLAPI_API_SECRET=YOUR_API_SECRET_KEY_HERE

examples/nextjs/.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# vercel
34+
.vercel
35+
36+
# typescript
37+
*.tsbuildinfo
38+
39+
# SOLAPI Setting
40+
.env
41+
42+
# TODO: 예제를 내려받고 나선 아래의 항목을 주석 해제 해주세요!
43+
# .env*
44+
# next-env.d.ts

examples/nextjs/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Next.js + SOLAPI SDK 예제
2+
3+
## 예제를 내려받았을 때 최초 실행 동작
4+
5+
예제를 내려받은 직후에는 아래와 같은 명령어를 입력해서 node_modules를 설치해주세요!
6+
7+
```shell
8+
npm install
9+
# or
10+
yarn install
11+
# or
12+
pnpm install
13+
# or
14+
bun install
15+
```
16+
17+
1. node_modules를 설치한 후에는 .env.example 파일을 .env로 변경해주세요!
18+
2. 바꾼 .env 파일로 들어가서 SOLAPI_API_KEY와 SOLAPI_API_SECRET의 값을 실제 사용하실 API Key, API Secret Key로 변경해주세요!
19+
20+
```text
21+
// .env
22+
SOLAPI_API_KEY=YOUR_API_KEY_HERE
23+
SOLAPI_API_SECRET=YOUR_API_SECRET_KEY_HERE
24+
```
25+
26+
## 실행해보기!
27+
28+
실행을 위해 터미널 환경에서 아래와 같은 명령어를 입력해주세요!
29+
30+
```shell
31+
npm run dev
32+
# or
33+
yarn dev
34+
# or
35+
pnpm dev
36+
# or
37+
bun dev
38+
39+
# 이후 localhost:3000 으로 접속해서 테스트를 진행하실 수 있습니다!
40+
```
41+
## 주의사항
42+
43+
반드시 .env 파일에 등록 및 활성화하신 API Key, API Secret Key를 설정하셔야 합니다!

examples/nextjs/envConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {loadEnvConfig} from '@next/env';
2+
3+
const projectDir = process.cwd();
4+
loadEnvConfig(projectDir);

examples/nextjs/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

examples/nextjs/next.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { NextConfig } from "next";
2+
3+
const nextConfig: NextConfig = {
4+
/* config options here */
5+
};
6+
7+
export default nextConfig;

examples/nextjs/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "solapi-nextjs-examples",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@next/env": "^15.2.1",
13+
"next": "15.2.1",
14+
"react": "^19.0.0",
15+
"react-dom": "^19.0.0",
16+
"solapi": "latest"
17+
},
18+
"devDependencies": {
19+
"@tailwindcss/postcss": "^4",
20+
"@types/node": "^20",
21+
"@types/react": "^19",
22+
"@types/react-dom": "^19",
23+
"tailwindcss": "^4",
24+
"typescript": "^5"
25+
}
26+
}

examples/nextjs/postcss.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
plugins: ["@tailwindcss/postcss"],
3+
};
4+
5+
export default config;

examples/nextjs/public/example.jpg

60.5 KB
Loading

examples/nextjs/src/app/actions.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use server';
2+
3+
import '../../envConfig';
4+
import {BadRequestError, SolapiMessageService} from 'solapi';
5+
import {redirect} from 'next/navigation';
6+
7+
export async function sendMessage(formData: FormData) {
8+
if (!formData.has('from') || !formData.has('to') || !formData.has('text')) {
9+
throw new BadRequestError(
10+
'반드시 발신번호, 수신번호, 메시지 내용을 입력해주세요!',
11+
);
12+
}
13+
const from = formData.get('from') as string;
14+
const to = formData.get('to') as string;
15+
const text = formData.get('text') as string;
16+
17+
const messageService = new SolapiMessageService(
18+
process.env.SOLAPI_API_KEY!,
19+
process.env.SOLAPI_API_SECRET!,
20+
);
21+
22+
await messageService
23+
.send({
24+
from,
25+
to,
26+
text,
27+
})
28+
.then(console.log);
29+
30+
redirect('/?success=true');
31+
}

0 commit comments

Comments
 (0)