Skip to content
Merged

Dev #37

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
5 changes: 4 additions & 1 deletion .github/workflows/nextjs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:

- name: client build
working-directory: client
env:
NEXT_PUBLIC_API_TARGET: prod
NEXT_PUBLIC_PROD_SERVER: ${{ secrets.PROD_SERVER_URL }}
run: npm run build

- name: deploy-client
Expand Down Expand Up @@ -95,7 +98,7 @@ jobs:
pm2 list || echo "PM2 list failed"

echo "=== Reloading nuon process ==="
pm2 reload nuon || pm2 start npm --name "nuon" -- start
pm2 reload nuon || pm2 start "sudo npm run start" --name "nuon" --time

echo "=== Final PM2 processes ==="
pm2 list
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/nextjs-dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:

- name: client build
working-directory: client
env:
NEXT_PUBLIC_API_TARGET: dev
NEXT_PUBLIC_DEV_SERVER: ${{ secrets.DEV_SERVER_URL }}
run: npm run build

- name: deploy-client
Expand Down Expand Up @@ -95,7 +98,7 @@ jobs:
pm2 list || echo "PM2 list failed"

echo "=== Reloading nuon-dev process ==="
pm2 reload nuon-dev || pm2 start npm --name "nuon-dev" -- start
pm2 reload nuon-dev || pm2 start "sudo npm run start " --name "nuon-dev" --time

echo "=== Final PM2 processes ==="
pm2 list
Expand Down
24 changes: 19 additions & 5 deletions client/src/config/axios.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import axios from "axios"
const PORT = 8000
const SERVER_URL =
process.env.NODE_ENV === "development"
? "http://localhost"
: "https://nuon.iubns.net"
let PORT = 8000

const getBaseUrl = () => {
const target = process.env.NEXT_PUBLIC_API_TARGET

switch (target) {
case "prod":
return process.env.NEXT_PUBLIC_PROD_SERVER
case "dev":
PORT = 8001
return process.env.NEXT_PUBLIC_DEV_SERVER
case "local":
default:
return process.env.NEXT_PUBLIC_LOCAL_SERVER
}
}

const SERVER_URL = getBaseUrl()

export const SERVER_FULL_PATH = `${SERVER_URL}:${PORT}`

const isBrowser = typeof window !== "undefined"
Expand Down
7 changes: 7 additions & 0 deletions client/src/hooks/useKakao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default function useKakaoHook() {

function getKakaoToken(): Promise<number> {
return new Promise((resolve, reject) => {
if (!Kakao) {
alert("카카오 SDK 로딩 실패\n잠시 후 다시 시도해주세요.")
if (globalValue.Kakao) {
alert("globalValue.Kakao는 불러와짐")
}
return
}
Kakao.Auth.login({
success: function (response: Response) {
Kakao.API.request({
Expand Down
27 changes: 21 additions & 6 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@ import dataSource from "./model/dataSource"
import cookieParser from "cookie-parser"

const app = express()
const port = 8000
let port = 8000

app.use(bodyParser.json())
app.use(cookieParser())
app.use(
cors({
origin: ["http://localhost:8080", "https://nuon.iubns.net"],
origin: [
"http://localhost:8080",
"https://nuon.iubns.net",
"https://nuon-dev.iubns.net",
],
credentials: true,
})
)
app.use("/", apiRouter)

const is_dev = process.env.NODE_ENV === "development"
const target = process.env.NEXT_PUBLIC_API_TARGET

var server

if (is_dev) {
if (target === "local") {
server = app
} else {
} else if (target === "dev") {
port = 8001
var privateKey = fs.readFileSync(
"/etc/letsencrypt/live/nuon-dev.iubns.net/privkey.pem"
)
var certificate = fs.readFileSync(
"/etc/letsencrypt/live/nuon-dev.iubns.net/cert.pem"
)
var ca = fs.readFileSync("/etc/letsencrypt/live/nuon-dev.iubns.net/chain.pem")
const credentials = { key: privateKey, cert: certificate, ca: ca }

server = https.createServer(credentials, app)
} else if (target === "prod") {
var privateKey = fs.readFileSync(
"/etc/letsencrypt/live/nuon.iubns.net/privkey.pem"
)
Expand All @@ -41,7 +57,6 @@ if (is_dev) {

server.listen(port, async () => {
await Promise.all([dataSource.initialize()])
//dataSource.dropDatabase()
console.log("start server")
})

Expand Down
61 changes: 22 additions & 39 deletions server/src/routes/soon/soonRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,42 @@ import {
userDatabase,
worshipScheduleDatabase,
} from "../../model/dataSource"
import { IsNull } from "typeorm"
import { checkJwt, getUserFromToken } from "../../util/util"
import { Community } from "../../entity/community"
import { User } from "../../entity/user"

const router = express.Router()

async function getAllSoonUsers(community: Community) {
const communityWithRelations = await communityDatabase.findOne({
where: { id: community.id },
relations: { children: true, users: true },
})
let users: User[] = []

const childUsersPromise = await communityWithRelations.children.map(
async (childCommunity) => {
return await getAllSoonUsers(childCommunity)
}
)
const awaitedChildUsers = (await Promise.all(childUsersPromise)).flat()

return [...communityWithRelations.users, ...awaitedChildUsers]
}

router.get("/my-group-info", async (req, res) => {
const user = await getUserFromToken(req)
if (!user) {
res.status(401).send({ error: "Unauthorized" })
return
}
const group = await communityDatabase.findOne({
select: {
id: true,
name: true,
users: {
id: true,
name: true,
yearOfBirth: true,
phone: true,
gender: true,
kakaoId: true,
},
children: true,
},
where: [
{
leader: {
id: user.id,
},
children: {
id: IsNull(),
},
},
{
deputyLeader: {
id: user.id,
},
children: {
id: IsNull(),
},
},
],
relations: {
users: true,
children: true,
},
})
const group = user.community
if (!group) {
res.status(404).send({ error: "Group not found" })
return
}
group.users = group.users.map(
const allUsers = await getAllSoonUsers(group)
group.users = allUsers.map(
(user) =>
({
id: user.id,
Expand Down