Skip to content

Commit

Permalink
Homepage (#17)
Browse files Browse the repository at this point in the history
* add homepage routes

* delete unnecessary public folder
  • Loading branch information
prestonlimlianjie authored Oct 23, 2019
1 parent 3abbc3c commit 9c2afee
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
11 changes: 10 additions & 1 deletion classes/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,13 @@ class DataType {
}
}

module.exports = { File, PageType, CollectionPageType, ResourcePageType, ResourceType, ImageType, DocumentType, DataType }
class HomepageType {
constructor() {
this.folderName = 'index.md'
}
getFolderName() {
return this.folderName
}
}

module.exports = { File, PageType, CollectionPageType, ResourcePageType, ResourceType, ImageType, DocumentType, DataType, HomepageType }
14 changes: 0 additions & 14 deletions public/stylesheets/style.css

This file was deleted.

56 changes: 56 additions & 0 deletions routes/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const express = require('express');
const router = express.Router();
const jwtUtils = require('../utils/jwt-utils')

// Import classes
const { File, HomepageType } = require('../classes/File.js')

// Constants
const HOMEPAGE_INDEX_PATH = '' // Empty string

// Read homepage index file
router.get('/:siteName/homepage', async function(req, res, next) {
try {
const { oauthtoken } = req.cookies
const { access_token } = jwtUtils.verifyToken(oauthtoken)

const { siteName } = req.params

const IsomerFile = new File(access_token, siteName)
const homepageType = new HomepageType()
IsomerFile.setFileType(homepageType)
const { sha, content } = await IsomerFile.read(HOMEPAGE_INDEX_PATH)

// TO-DO:
// Validate content

res.status(200).json({ content, sha })
} catch (err) {
console.log(err)
}
})

// Update homepage index file
router.post('/:siteName/homepage', async function(req, res, next) {
try {
const { oauthtoken } = req.cookies
const { access_token } = jwtUtils.verifyToken(oauthtoken)

const { siteName } = req.params
const { content, sha } = req.body

// TO-DO:
// Validate content

const IsomerFile = new File(access_token, siteName)
const homepageType = new HomepageType()
IsomerFile.setFileType(homepageType)
const { newSha } = await IsomerFile.update(HOMEPAGE_INDEX_PATH, content, sha)

res.status(200).json({ content, sha: newSha })
} catch (err) {
console.log(err)
}
})

module.exports = router;
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const resourcePagesRouter = require('./routes/resourcePages')
const imagesRouter = require('./routes/images')
const documentsRouter = require('./routes/documents')
const menuRouter = require('./routes/menus')
const homepageRouter = require('./routes/homepage')

const app = express();

Expand Down Expand Up @@ -48,6 +49,7 @@ app.use('/sites', resourcePagesRouter)
app.use('/sites', imagesRouter)
app.use('/sites', documentsRouter)
app.use('/sites', menuRouter)
app.use('/sites', homepageRouter)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down

0 comments on commit 9c2afee

Please sign in to comment.