mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 10:39:09 +00:00
lerna: split up bulk of packages
This commit is contained in:
parent
cb0b1d2410
commit
47a2e5694e
90 changed files with 0 additions and 0 deletions
37
packages/roleypoly-server/api/ui.js
Normal file
37
packages/roleypoly-server/api/ui.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
// @flow
|
||||
import { type Context } from 'koa'
|
||||
import { type AppContext, type Router } from '../Roleypoly'
|
||||
export default (R: Router, $: AppContext) => {
|
||||
// note, this file only contains stuff for complicated routes.
|
||||
// next.js will handle anything beyond this.
|
||||
const processMappings = (mapping: { [path: string]: { path: string, noAutoFix?: boolean } }) => {
|
||||
for (let p in mapping) {
|
||||
R.get(p, (ctx: Context) => {
|
||||
ctx.status = 200
|
||||
return $.ui.render(ctx.req, ctx.res, mapping[p].path || mapping[p], { ...ctx.query, ...ctx.params })
|
||||
})
|
||||
|
||||
const { path } = mapping[p]
|
||||
if (!mapping[p].noAutoFix) {
|
||||
R.get(path, ctx => ctx.redirect(p))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processMappings({
|
||||
'/s/add': { path: '/_internal/_server_add' },
|
||||
'/s/:id': { path: '/_internal/_server', noAutoFix: true },
|
||||
'/test': { path: '/test_wwsw' }
|
||||
})
|
||||
|
||||
// edge cases
|
||||
R.get('/_internal/_server', (ctx: Context) => {
|
||||
if (ctx.query.id) {
|
||||
return ctx.redirect(`/s/${ctx.query.id}`)
|
||||
}
|
||||
|
||||
return ctx.redirect('/s/add')
|
||||
})
|
||||
|
||||
R.get('/s/', (ctx: Context) => ctx.redirect('/s/add'))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue