- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
const serve = require('koa-static')
const app = websockify(new Koa())
const router = new Router()
const koabody = new koaBody({
multipart: true,
formidable: {uploadDir: os.tmpdir()}
})
app
.use(session({key:'SESSION', store: new Store()}))
.use(cors())
.use(serve(path.join(__dirname, '/public/'), {}))
.use(router.routes())
.use(router.allowedMethods())
;
router
.get('/pages' , route.pages.getPages)
.post('/page' , koabody, route.pages.upsertPage)
.put('/page/:id' , koabody, route.pages.upsertPage)
.delete('/page/:id' , koabody, route.pages.deletePage)
.get('/promosets' , route.promosets.getPromosets)
.post('/promoset' , koabody, route.promosets.upsertPromoset)
.put('/promoset/:id' , koabody, route.promosets.upsertPromoset)
.get('/crescendos' , route.crescendos.getCrescendos)
.get('/mastheads' , route.mastheads.getMastheads)
.post('/upload-masthteads' , koabody, route.mastheads.uploadMastheads)
.get('/masthead-types' , route.mastheads.getMastheadTypes)
.get('/flips' , route.flips.getFlips)
.post('/flip' , koabody, route.flips.upsertFlip)
.put('/flip/:id' , koabody, route.flips.upsertFlip)
.post('/login' , koabody, route.auth.login)
.post('/upload/:cat' , koabody, (ctx, next) => route.upload[ctx.params.cat](ctx, next))
;
/****************************************************
* Initial setup "script". Just create needed files
* if they don't yet exist
****************************************************/
// Create pages.json (it should certainly already exist though)
fs.readJson(cfg.files.pages, (e, data) => {
if (!data) {
fs.outputFileSync(cfg.files.pages, '[]')
}
})
// Create promosets.json (it should certainly already exist though)
fs.readJson(cfg.files.promosets, (e, data) => {
if (!data) {
fs.outputFileSync(cfg.files.promosets, '{}')
}
})
// Create our schedule.json file with [] in it
fs.readJson(cfg.files.schedule, (e, data) => {
if (!data) {
fs.outputFileSync(cfg.files.schedule, '[]')
}
})
// Create our files dir
fs.ensureDirSync(cfg.dirs.flipFiles)
// Create our public dir so we can serve masthead imgs, etc
fs.ensureDirSync(cfg.dirs.public)
// Create symbolic mastheads folder
fs.ensureSymlinkSync(`${cfg['dirs']['mastheads']}`, `${cfg['dirs']['mastheadsSymlink']}`)