Skip to content

Commit

Permalink
fix(website): turn website domain to array;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed May 15, 2022
1 parent 441970b commit e51993a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/app-console/src/views/storage/websites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default {
this.websites = ret.data.map(item => {
item.created_at = dayjs(item.created_at).format('YYYY-MM-DD HH:mm:ss')
item.updated_at = dayjs(item.updated_at).format('YYYY-MM-DD HH:mm:ss')
item.domain = item.domain.join(',')
return item
})
this.loading = false
Expand Down Expand Up @@ -250,6 +251,10 @@ export default {
return showError('解析错误,请使用正确的 CNAME 解析值')
}
if(ret.code === 'ALREADY_EXISTED') {
return showError('该域名已经被绑定')
}
this.$notify({
type: 'success',
title: '操作成功',
Expand Down
11 changes: 7 additions & 4 deletions packages/system-server/src/handler/website/domain-bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { CONST_DICTS } from "../../constants"
import { checkPermission } from "../../support/permission"
import { IApplicationData } from "../../support/application"
import { DatabaseAgent } from "../../db"
import { logger } from "../../support/logger"
// import { handleCheckDomain } from "./domain-check"


/**
* handle bind a domain to a website
Expand Down Expand Up @@ -45,7 +44,7 @@ export async function handleBindDomain(req: Request, res: Response) {
}

// check domain is available
const resolver = new dns.promises.Resolver({ timeout: 3000, tries: 2 })
const resolver = new dns.promises.Resolver({ timeout: 3000, tries: 1 })
const result = await resolver.resolveCname(domain as string).catch(() => { })
if (!result) {
return res.send({ code: 'DOMAIN_NOT_RESOLVEABLE', error: 'domain is not resolveable' })
Expand All @@ -59,14 +58,18 @@ export async function handleBindDomain(req: Request, res: Response) {
const existedDomain = await db
.collection(CN_WEBSITE_HOSTING)
.countDocuments({ domain, status: { $ne: "deleted" } })

if (existedDomain) {
return res.send({ code: 'ALREADY_EXISTED', error: "domain already binded" })
}

// bind
const r = await db.collection(CN_WEBSITE_HOSTING).updateOne(
{ _id: new ObjectId(website_id), appid: app.appid },
{ $set: { domain, state: "pending", updated_at: new Date() } }
{
$set: { state: "pending", updated_at: new Date() },
$push: { domain: domain }
}
)

return res.send({ data: r.modifiedCount })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function handleCreateWebsite(req: Request, res: Response) {
label,
bucket_name: bucket,
appid: app.appid,
domain: null,
domain: [] as string[],
cname,
status: 'enabled', // 'enabled' | 'disabled' | 'deleted' , the logic status of website
state: 'pending', // 'created' | 'deleted' | 'pending', the real state of website
Expand Down

0 comments on commit e51993a

Please sign in to comment.