Skip to content
Open
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
16 changes: 13 additions & 3 deletions document/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ components:
createdAt:
type: string
format: date-time
domain:
type: string
protocol:
type: boolean
Preset:
type: object
properties:
Expand All @@ -211,9 +215,6 @@ components:
PullSetting:
type: object
properties:
pullUrl:
type: string
example: 'https://demo.com'
allowedOrigins:
type: array
items:
Expand Down Expand Up @@ -598,6 +599,15 @@ paths:
provider:
type: string
example: cloudfront
domain:
type: string
protocol:
type: string
required:
- domain
- name
- provider
- protocol
responses:
'201':
description: CREATED
Expand Down
5 changes: 5 additions & 0 deletions src/functions/project/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import projectService from 'services/project'
import authorize from 'middlewares/authorize'
import config from 'infrastructure/config'

//use url regex on this site: https://regexr.com/3au3g
const DOMAIN_REGEX = /^(?:[a-z\d](?:[a-z\d-]{0,63}[a-z\d])?\.)+[a-z\d][a-z\d-]{0,63}[a-z\d]$/i

const SCHEMA = joi.object().keys({
name: joi.string().max(50).trim().required(),
domain: joi.string().required().regex(DOMAIN_REGEX),
protocol: joi.string().valid([ 'http', 'https' ]).required(),
provider: joi.any().valid('cloudfront').required()
})

Expand Down
1 change: 0 additions & 1 deletion src/functions/project/pull-setting/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import authorize from 'middlewares/authorize'
import config from 'infrastructure/config'

const SCHEMA = joi.object().keys({
pullUrl: joi.string().allow('').trim(),
allowedOrigins: joi.array().items(
joi.string().trim()
),
Expand Down
8 changes: 8 additions & 0 deletions src/models/project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import mongoose, { register } from 'infrastructure/mongoose'

const schema = mongoose.Schema({
domain: {
type: String,
required: true
},
protocol: {
type: String,
required: true
},
name: {
type: String,
required: true
Expand Down
3 changes: 0 additions & 3 deletions src/models/pull-setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const schema = mongoose.Schema({
name: String,
value: String
} ],
pullUrl: {
type: String
},
allowedOrigins: [ String ]
}, {
collection: 'pullSettings',
Expand Down
12 changes: 10 additions & 2 deletions src/services/project/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ const generateUniqueIdentifier = async (retry) => {
return await generateUniqueIdentifier(retry - 1)
}

const create = async ({ name, provider, owner }) => {
const create = async ({
domain,
owner,
name,
protocol,
provider
}) => {
const identifier = await generateUniqueIdentifier(10)

const Project = await createProjectModel()

const project = await new Project({
name,
domain,
identifier,
name,
protocol,
status: 'INITIALIZING'
}).save()

Expand Down
4 changes: 3 additions & 1 deletion src/transformers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export default (project) => ({
status: project.status,
isActive: project.isActive,
isDeleted: project.isDeleted,
createdAt: project.createdAt
createdAt: project.createdAt,
domain: project.domain,
protocol: project.protocol
})
1 change: 0 additions & 1 deletion src/transformers/pull-setting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default (pullSetting) => ({
pullUrl: pullSetting.pullUrl,
allowedOrigins: pullSetting.allowedOrigins,
headers: pullSetting.headers.map(
(header) => ({
Expand Down