From ef0190fc89af2c3aed0d28ec525672e4ade76475 Mon Sep 17 00:00:00 2001 From: Preston Lim Date: Wed, 27 Nov 2019 16:05:23 +0800 Subject: [PATCH 1/3] feat: setup deploy to staging (#34) --- .travis.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e8578808b..88c1073e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ branches: # This script will be run on the following branches only only: - master + - staging install: - npm install after_success: @@ -22,4 +23,15 @@ deploy: env: "TestCms-env" bucket_name: "test-cms-isomer" on: - branch: master \ No newline at end of file + branch: master + - provider: elasticbeanstalk + access_key_id: $AWS_ACCESS_KEY_ID_FOR_DEPLOYMENT + secret_access_key: $AWS_SECRET_ACCESS_KEY_FOR_DEPLOYMENT + region: "ap-southeast-1" + skip_cleanup: true + zip_file: $ELASTICBEANSTALK_DEPLOYMENT_ZIP_FILE + app: "test-cms" + env: "isomercms-backend-staging" + bucket_name: "isomercms-backend-staging" + on: + branch: staging \ No newline at end of file From 3e2429021a1bb69585a75d34415549ce302787e3 Mon Sep 17 00:00:00 2001 From: kwajiehao <31984694+kwajiehao@users.noreply.github.com> Date: Fri, 6 Dec 2019 18:28:47 +0800 Subject: [PATCH 2/3] Revert "feat: setup deploy to staging (#34)" (#47) This reverts commit ef0190fc89af2c3aed0d28ec525672e4ade76475. --- .travis.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88c1073e8..e8578808b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ branches: # This script will be run on the following branches only only: - master - - staging install: - npm install after_success: @@ -23,15 +22,4 @@ deploy: env: "TestCms-env" bucket_name: "test-cms-isomer" on: - branch: master - - provider: elasticbeanstalk - access_key_id: $AWS_ACCESS_KEY_ID_FOR_DEPLOYMENT - secret_access_key: $AWS_SECRET_ACCESS_KEY_FOR_DEPLOYMENT - region: "ap-southeast-1" - skip_cleanup: true - zip_file: $ELASTICBEANSTALK_DEPLOYMENT_ZIP_FILE - app: "test-cms" - env: "isomercms-backend-staging" - bucket_name: "isomercms-backend-staging" - on: - branch: staging \ No newline at end of file + branch: master \ No newline at end of file From 9e86e8fe9220f98dc2c8bc16ffb48a02bc719fe2 Mon Sep 17 00:00:00 2001 From: kwajiehao <31984694+kwajiehao@users.noreply.github.com> Date: Fri, 11 Dec 2020 11:14:46 +0800 Subject: [PATCH 3/3] chore: add `/v1` to all URI paths (#95) This commit adds a `/v1` prefix to all URI paths to version our API. This will be useful for several reasons: - allows us to gracefully accommodate a v2 api which uses github's graphql API - allows us to craft tight firewall rules (currently, we search for whether a URI path contains `/sites` or `/auth`, which would allow nonsense URI paths like `/authors`) Co-authored-by: Jie Hao Kwa --- docs/openapi.yaml | 54 ++++++++++----------- middleware/auth.js | 115 +++++++++++++++++++++++---------------------- server.js | 32 ++++++------- 3 files changed, 101 insertions(+), 100 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index ca47c58a7..fbc67a8a7 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -213,7 +213,7 @@ components: paths: - /: + /v1: get: tags: - Authentication @@ -225,7 +225,7 @@ paths: application/json: schema: $ref: "#/components/schemas/OAuthParams" - /sites/{siteName}/collections: + /v1/sites/{siteName}/collections: get: tags: - Collections @@ -265,7 +265,7 @@ paths: application/json: schema: $ref: "#/components/schemas/CollectionNameResponse" - /sites/{siteName}/collections/{collectionName}: + /v1/sites/{siteName}/collections/{collectionName}: get: tags: - Collection Pages @@ -310,7 +310,7 @@ paths: application/json: schema: $ref: "#/components/schemas/CollectionNameResponse" - /sites/{siteName}/collections/{collectionName}/rename/{newCollectionName}: + /v1/sites/{siteName}/collections/{collectionName}/rename/{newCollectionName}: post: tags: - Collections @@ -343,7 +343,7 @@ paths: application/json: schema: $ref: "#/components/schemas/RenameCollection" - /sites/{siteName}/collections/{collectionName}/pages: + /v1/sites/{siteName}/collections/{collectionName}/pages: post: tags: - Collection Pages @@ -371,7 +371,7 @@ paths: application/json: schema: $ref: "#/components/schemas/CollectionListResponse" - /sites/{siteName}/collections/{collectionName}/pages/{pageName}: + /v1/sites/{siteName}/collections/{collectionName}/pages/{pageName}: get: tags: - Collection Pages @@ -459,7 +459,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/collections/{collectionName}/pages/{pageName}/rename/{newPageName}: + /v1/sites/{siteName}/collections/{collectionName}/pages/{pageName}/rename/{newPageName}: post: tags: - Collection Pages @@ -498,7 +498,7 @@ paths: schema: $ref: "#/components/schemas/CollectionPageResponse" - /sites/{siteName}/pages: + /v1/sites/{siteName}/pages: get: tags: - Pages @@ -543,7 +543,7 @@ paths: application/json: schema: $ref: "#/components/schemas/PageResponse" - /sites/{siteName}/pages/{pageName}: + /v1/sites/{siteName}/pages/{pageName}: get: tags: - Pages @@ -616,7 +616,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/pages/{pageName}/rename/{newPageName}: + /v1/sites/{siteName}/pages/{pageName}/rename/{newPageName}: post: tags: - Pages @@ -650,7 +650,7 @@ paths: schema: $ref: "#/components/schemas/PageResponse" - /sites/{siteName}/documents: + /v1/sites/{siteName}/documents: get: tags: - Documents @@ -690,7 +690,7 @@ paths: application/json: schema: $ref: "#/components/schemas/DocumentResponse" - /sites/{siteName}/documents/{documentName}: + /v1/sites/{siteName}/documents/{documentName}: get: tags: - Documents @@ -763,7 +763,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/documents/{documentName}/rename/{newDocumentName}: + /v1/sites/{siteName}/documents/{documentName}/rename/{newDocumentName}: post: tags: - Documents @@ -797,7 +797,7 @@ paths: schema: $ref: "#/components/schemas/DocumentResponse" - /sites/{siteName}/images: + /v1/sites/{siteName}/images: get: tags: - Images @@ -837,7 +837,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ImageResponse" - /sites/{siteName}/images/{imageName}: + /v1/sites/{siteName}/images/{imageName}: get: tags: - Images @@ -910,7 +910,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/images/{imageName}/rename/{newImageName}: + /v1/sites/{siteName}/images/{imageName}/rename/{newImageName}: post: tags: - Images @@ -943,7 +943,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ImageResponse" - /sites: + /v1/sites: get: tags: - Sites @@ -956,7 +956,7 @@ paths: schema: $ref: "#/components/schemas/SiteListResponse" - /sites/{siteName}/resource-room: + /v1/sites/{siteName}/resource-room: get: tags: - Resource Room @@ -1009,7 +1009,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/resource-room/{resourceRoom}: + /v1/sites/{siteName}/resource-room/{resourceRoom}: post: tags: - Resource Room @@ -1032,7 +1032,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourceRoom" - /sites/{siteName}/resources: + /v1/sites/{siteName}/resources: get: tags: - Resources @@ -1072,7 +1072,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourceResponse" - /sites/{siteName}/resources/{resourceName}: + /v1/sites/{siteName}/resources/{resourceName}: get: tags: - Resource Pages @@ -1113,7 +1113,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/resources/{resourceName}/rename/{newResourceName}: + /v1/sites/{siteName}/resources/{resourceName}/rename/{newResourceName}: post: tags: - Resources @@ -1141,7 +1141,7 @@ paths: application/json: schema: $ref: "#/components/schemas/RenameResource" - /sites/{siteName}/resources/{resourceName}/pages: + /v1/sites/{siteName}/resources/{resourceName}/pages: post: tags: - Resource Pages @@ -1169,7 +1169,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourcePageResponse" - /sites/{siteName}/resources/{resourceName}/pages/{pageName}: + /v1/sites/{siteName}/resources/{resourceName}/pages/{pageName}: get: tags: - Resource Pages @@ -1257,7 +1257,7 @@ paths: responses: 200: description: Success - /sites/{siteName}/resources/{resourceName}/pages/{pageName}/rename/{newPageName}: + /v1/sites/{siteName}/resources/{resourceName}/pages/{pageName}/rename/{newPageName}: post: tags: - Resource Pages @@ -1295,7 +1295,7 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourcePageResponse" - /sites/{siteName}/menus: + /v1/sites/{siteName}/menus: get: tags: - Menus @@ -1313,7 +1313,7 @@ paths: application/json: schema: $ref: "#/components/schemas/MenuListResponse" - /sites/{siteName}/menus/{menuName}: + /v1/sites/{siteName}/menus/{menuName}: get: tags: - Menus diff --git a/middleware/auth.js b/middleware/auth.js index 88855bfe3..99dd0b07e 100644 --- a/middleware/auth.js +++ b/middleware/auth.js @@ -37,93 +37,94 @@ const verifyJwt = (req, res, next) => { } // Login and logout -auth.get('/auth', noVerify) -auth.get('/auth/logout', noVerify) +auth.get('/v1/auth', noVerify) +auth.get('/v1/auth/logout', noVerify) // Index -auth.get('/', noVerify) +auth.get('/v1', noVerify) // Homepage -auth.get('/sites/:siteName/homepage', verifyJwt) -auth.post('/sites/:siteName/homepage', verifyJwt) +auth.get('/v1/sites/:siteName/homepage', verifyJwt) +auth.post('/v1/sites/:siteName/homepage', verifyJwt) // Collection pages -auth.get('/sites/:siteName/collections/:collectionName', verifyJwt) -auth.get('/sites/:siteName/collections/:collectionName/pages', verifyJwt) -auth.post('/sites/:siteName/collections/:collectionName/pages', verifyJwt) -auth.get('/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) -auth.delete('/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/collections/:collectionName/pages/:pageName/rename/:newPageName', verifyJwt) +auth.get('/v1/sites/:siteName/collections/:collectionName', verifyJwt) +auth.get('/v1/sites/:siteName/collections/:collectionName/pages', verifyJwt) +auth.post('/v1/sites/:siteName/collections/:collectionName/pages', verifyJwt) +auth.get('/v1/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) +auth.delete('/v1/sites/:siteName/collections/:collectionName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/collections/:collectionName/pages/:pageName/rename/:newPageName', verifyJwt) // Collections -auth.get('/sites/:siteName/collections', verifyJwt) -auth.post('/sites/:siteName/collections', verifyJwt) -auth.delete('/sites/:siteName/collections/:collectionName', verifyJwt) -auth.post('/sites/:siteName/collections/:collectionName/rename/:newCollectionName', verifyJwt) +auth.get('/v1/sites/:siteName/collections', verifyJwt) +auth.post('/v1/sites/:siteName/collections', verifyJwt) +auth.delete('/v1/sites/:siteName/collections/:collectionName', verifyJwt) +auth.post('/v1/sites/:siteName/collections/:collectionName/rename/:newCollectionName', verifyJwt) // Documents -auth.get('/sites/:siteName/documents', verifyJwt) -auth.post('/sites/:siteName/documents', verifyJwt) -auth.get('/sites/:siteName/documents/:documentName', verifyJwt) -auth.post('/sites/:siteName/documents/:documentName', verifyJwt) -auth.delete('/sites/:siteName/documents/:documentName', verifyJwt) -auth.post('/sites/:siteName/documents/:documentName/rename/:newDocumentName', verifyJwt) +auth.get('/v1/sites/:siteName/documents', verifyJwt) +auth.post('/v1/sites/:siteName/documents', verifyJwt) +auth.get('/v1/sites/:siteName/documents/:documentName', verifyJwt) +auth.post('/v1/sites/:siteName/documents/:documentName', verifyJwt) +auth.delete('/v1/sites/:siteName/documents/:documentName', verifyJwt) +auth.post('/v1/sites/:siteName/documents/:documentName/rename/:newDocumentName', verifyJwt) // Images -auth.get('/sites/:siteName/images', verifyJwt) -auth.post('/sites/:siteName/images', verifyJwt) -auth.get('/sites/:siteName/images/:imageName', verifyJwt) -auth.post('/sites/:siteName/images/:imageName', verifyJwt) -auth.delete('/sites/:siteName/images/:imageName', verifyJwt) -auth.post('/sites/:siteName/images/:imageName/rename/:newImageName', verifyJwt) +auth.get('/v1/sites/:siteName/images', verifyJwt) +auth.post('v/sites/:siteName/images', verifyJwt) +auth.get('/v1/sites/:siteName/images/:imageName', verifyJwt) +auth.post('/v1/sites/:siteName/images/:imageName', verifyJwt) +auth.delete('/v1/sites/:siteName/images/:imageName', verifyJwt) +auth.post('/v1/sites/:siteName/images/:imageName/rename/:newImageName', verifyJwt) // Menu directory -auth.get('/sites/:siteName/tree', verifyJwt) +auth.get('/v1/sites/:siteName/tree', verifyJwt) // Menu -auth.get('/sites/:siteName/menus', verifyJwt) -auth.get('/sites/:siteName/menus/:menuName', verifyJwt) -auth.post('/sites/:siteName/menus/:menuName', verifyJwt) +auth.get('/v1/sites/:siteName/menus', verifyJwt) +auth.get('/v1/sites/:siteName/menus/:menuName', verifyJwt) +auth.post('/v1/sites/:siteName/menus/:menuName', verifyJwt) // Pages -auth.get('/sites/:siteName/pages', verifyJwt) -auth.get('/sites/:siteName/unlinkedPages', verifyJwt) -auth.post('/sites/:siteName/pages', verifyJwt) -auth.get('/sites/:siteName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/pages/:pageName', verifyJwt) -auth.delete('/sites/:siteName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/pages/:pageName/rename/:newPageName', verifyJwt) +auth.get('/v1/sites/:siteName/pages', verifyJwt) +auth.get('/v1/sites/:siteName/unlinkedPages', verifyJwt) +auth.post('/v1/sites/:siteName/pages', verifyJwt) +auth.get('/v1/sites/:siteName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/pages/:pageName', verifyJwt) +auth.delete('/v1/sites/:siteName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/pages/:pageName/rename/:newPageName', verifyJwt) // Resource pages -auth.get('/sites/:siteName/resources/:resourceName', verifyJwt) -auth.post('/sites/:siteName/resources/:resourceName/pages', verifyJwt) -auth.get('/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) -auth.delete('/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) -auth.post('/sites/:siteName/resources/:resourceName/pages/:pageName/rename/:newPageName', verifyJwt) +auth.get('/v1/sites/:siteName/resources/:resourceName', verifyJwt) +auth.post('/v1/sites/:siteName/resources/:resourceName/pages', verifyJwt) +auth.get('/v1/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) +auth.delete('/v1/sites/:siteName/resources/:resourceName/pages/:pageName', verifyJwt) +auth.post('/v1/sites/:siteName/resources/:resourceName/pages/:pageName/rename/:newPageName', verifyJwt) // Resource room -auth.get('/sites/:siteName/resource-room', verifyJwt) -auth.post('/sites/:siteName/resource-room', verifyJwt) -auth.post('/sites/:siteName/resource-room/:resourceRoom', verifyJwt) -auth.delete('/sites/:siteName/resource-room', verifyJwt) +auth.get('/v1/sites/:siteName/resource-room', verifyJwt) +auth.post('/v1/sites/:siteName/resource-room', verifyJwt) +auth.post('/v1/sites/:siteName/resource-room/:resourceRoom', verifyJwt) +auth.delete('/v1/sites/:siteName/resource-room', verifyJwt) // Resources -auth.get('/sites/:siteName/resources', verifyJwt) -auth.post('/sites/:siteName/resources', verifyJwt) -auth.delete('/sites/:siteName/resources/:resourceName', verifyJwt) -auth.post('/sites/:siteName/resources/:resourceName/rename/:newResourceName', verifyJwt) +auth.get('/v1/sites/:siteName/resources', verifyJwt) +auth.post('/v1/sites/:siteName/resources', verifyJwt) +auth.delete('/v1/sites/:siteName/resources/:resourceName', verifyJwt) +auth.post('/v1/sites/:siteName/resources/:resourceName/rename/:newResourceName', verifyJwt) // Settings -auth.get('/sites/:siteName/settings', verifyJwt) -auth.post('/sites/:siteName/settings', verifyJwt) +auth.get('/v1/sites/:siteName/settings', verifyJwt) +auth.post('/v1/sites/:siteName/settings', verifyJwt) // Netlify toml -auth.get('/sites/:siteName/netlify-toml', verifyJwt) +auth.get('/v1/sites/:siteName/netlify-toml', verifyJwt) // Sites -auth.get('/sites', verifyJwt) +auth.get('/v1/sites', verifyJwt) +auth.get('/v1/sites/:siteName', verifyJwt) auth.use((req, res, next) => { if (!req.route) { diff --git a/server.js b/server.js index 219a99e62..82e8dd0ea 100644 --- a/server.js +++ b/server.js @@ -51,22 +51,22 @@ app.use(auth) app.use(apiLogger) // Routes layer setup -app.use('/', indexRouter); -app.use('/auth', authRouter); -app.use('/sites', sitesRouter) -app.use('/sites', pagesRouter) -app.use('/sites', collectionsRouter) -app.use('/sites', collectionPagesRouter) -app.use('/sites', resourceRoomRouter) -app.use('/sites', resourcesRouter) -app.use('/sites', resourcePagesRouter) -app.use('/sites', imagesRouter) -app.use('/sites', documentsRouter) -app.use('/sites', menuRouter) -app.use('/sites', homepageRouter) -app.use('/sites', menuDirectoryRouter) -app.use('/sites', settingsRouter) -app.use('/sites', netlifyTomlRouter) +app.use('/v1', indexRouter); +app.use('/v1/auth', authRouter); +app.use('/v1/sites', sitesRouter) +app.use('/v1/sites', pagesRouter) +app.use('/v1/sites', collectionsRouter) +app.use('/v1/sites', collectionPagesRouter) +app.use('/v1/sites', resourceRoomRouter) +app.use('/v1/sites', resourcesRouter) +app.use('/v1/sites', resourcePagesRouter) +app.use('/v1/sites', imagesRouter) +app.use('/v1/sites', documentsRouter) +app.use('/v1/sites', menuRouter) +app.use('/v1/sites', homepageRouter) +app.use('/v1/sites', menuDirectoryRouter) +app.use('/v1/sites', settingsRouter) +app.use('/v1/sites', netlifyTomlRouter) // catch 404 and forward to error handler app.use(function(req, res, next) {