further simplification of server code
This commit is contained in:
parent
87ad6647df
commit
a28322f538
|
@ -30,34 +30,9 @@
|
||||||
let selectedCategory = categories[0]
|
let selectedCategory = categories[0]
|
||||||
|
|
||||||
const onComponentChosen = component => {
|
const onComponentChosen = component => {
|
||||||
if (component.template) {
|
|
||||||
// onTemplateChosen(component.template)
|
|
||||||
} else {
|
|
||||||
store.addChildComponent(component._component)
|
store.addChildComponent(component._component)
|
||||||
toggleTab()
|
toggleTab()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// const onTemplateInstanceChosen = () => {
|
|
||||||
// selectedComponent = null
|
|
||||||
// const instance = templateInstances.find(
|
|
||||||
// i => i.name === selectedTemplateInstance
|
|
||||||
// )
|
|
||||||
// store.addTemplatedComponent(instance.props)
|
|
||||||
// toggleTab()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $: templatesByComponent = groupBy(t => t.component)($store.templates)
|
|
||||||
// $: standaloneTemplates = pipe(
|
|
||||||
// templatesByComponent,
|
|
||||||
// [
|
|
||||||
// values,
|
|
||||||
// flatten,
|
|
||||||
// filter(t => !$store.components.some(c => c.name === t.component)),
|
|
||||||
// map(t => ({ name: splitName(t.component).componentName, template: t })),
|
|
||||||
// uniqBy(t => t.name),
|
|
||||||
// ]
|
|
||||||
// )
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root">
|
<div class="root">
|
||||||
|
@ -78,25 +53,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <ConfirmDialog
|
|
||||||
bind:this={selectTemplateDialog}
|
|
||||||
title="Choose Template"
|
|
||||||
onCancel={() => (selectedComponent = null)}
|
|
||||||
onOk={onTemplateInstanceChosen}>
|
|
||||||
{#each templateInstances.map(i => i.name) as instance}
|
|
||||||
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid">
|
|
||||||
<label>
|
|
||||||
<input
|
|
||||||
class="uk-radio"
|
|
||||||
type="radio"
|
|
||||||
bind:group={selectedTemplateInstance}
|
|
||||||
value={instance} />
|
|
||||||
<span class="template-instance-label">{instance}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</ConfirmDialog> -->
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.tabs {
|
.tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -18,7 +18,6 @@ const {
|
||||||
componentRoutes,
|
componentRoutes,
|
||||||
} = require("./routes")
|
} = require("./routes")
|
||||||
|
|
||||||
module.exports = app => {
|
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
|
@ -34,10 +33,9 @@ module.exports = app => {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.use(async (ctx, next) => {
|
.use(async (ctx, next) => {
|
||||||
// TODO: temp dev middleware
|
|
||||||
ctx.config = {
|
ctx.config = {
|
||||||
latestPackagesFolder: resolve(homedir(), ".budibase"),
|
latestPackagesFolder: resolve(homedir(), ".budibase"),
|
||||||
jwtSecret: "foo",
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
}
|
}
|
||||||
ctx.isDev = process.env.NODE_ENV !== "production"
|
ctx.isDev = process.env.NODE_ENV !== "production"
|
||||||
await next()
|
await next()
|
||||||
|
@ -95,5 +93,4 @@ module.exports = app => {
|
||||||
|
|
||||||
router.redirect("/", "/_builder")
|
router.redirect("/", "/_builder")
|
||||||
|
|
||||||
return router
|
module.exports = router
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
const Koa = require("koa")
|
const Koa = require("koa")
|
||||||
const logger = require("koa-logger")
|
const logger = require("koa-logger")
|
||||||
const router = require("./api")
|
const api = require("./api")
|
||||||
const koaBody = require("koa-body")
|
const koaBody = require("koa-body")
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
|
|
||||||
module.exports = () => {
|
// set up top level koa middleware
|
||||||
app.keys = Object.keys(process.env)
|
|
||||||
.filter(k => k.startsWith("COOKIE_KEY_"))
|
|
||||||
.map(k => process.env[k])
|
|
||||||
|
|
||||||
app.use(koaBody({ multipart: true }))
|
app.use(koaBody({ multipart: true }))
|
||||||
app.use(logger())
|
app.use(logger())
|
||||||
app.use(router(app).routes())
|
|
||||||
|
|
||||||
return app.listen(process.env.PORT || 4001)
|
// api routes
|
||||||
}
|
app.use(api.routes())
|
||||||
|
|
||||||
|
module.exports = app.listen(process.env.PORT || 4001)
|
||||||
|
|
|
@ -5,7 +5,7 @@ require("dotenv").config()
|
||||||
const DEV_URL = "http://localhost:4001";
|
const DEV_URL = "http://localhost:4001";
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
app.server = require("./app")();
|
app.server = require("./app");
|
||||||
let win = new BrowserWindow({ width: 1920, height: 1080 });
|
let win = new BrowserWindow({ width: 1920, height: 1080 });
|
||||||
win.loadURL(DEV_URL);
|
win.loadURL(DEV_URL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
require("dotenv").config()
|
require("dotenv").config()
|
||||||
const app = require("./app")
|
const server = require("./app")
|
||||||
|
|
||||||
async function startServer() {
|
|
||||||
const server = await app()
|
|
||||||
server.on("listening", () => {
|
server.on("listening", () => {
|
||||||
console.log(`Budibase Server listening on port ${process.env.PORT}`)
|
console.log(`Budibase Server listening on port ${process.env.PORT}`)
|
||||||
})
|
});
|
||||||
}
|
|
||||||
|
|
||||||
startServer()
|
|
|
@ -1,8 +1,14 @@
|
||||||
const jwt = require("jsonwebtoken")
|
const jwt = require("jsonwebtoken")
|
||||||
|
const STATUS_CODES = require("../utilities/statusCodes");
|
||||||
|
|
||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
|
if (ctx.isDev) {
|
||||||
|
ctx.isAuthenticated = true
|
||||||
|
await next();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const token = ctx.cookies.get("budibase:token")
|
const token = ctx.cookies.get("budibase:token")
|
||||||
console.log("TOKEN", token)
|
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
ctx.isAuthenticated = false
|
ctx.isAuthenticated = false
|
||||||
|
@ -14,7 +20,7 @@ module.exports = async (ctx, next) => {
|
||||||
ctx.jwtPayload = jwt.verify(token, ctx.config.jwtSecret)
|
ctx.jwtPayload = jwt.verify(token, ctx.config.jwtSecret)
|
||||||
ctx.isAuthenticated = true
|
ctx.isAuthenticated = true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(err.status || 403, err.text)
|
ctx.throw(err.status || STATUS_CODES.FORBIDDEN, err.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
await next()
|
await next()
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
const session = require("koa-session")
|
|
||||||
|
|
||||||
module.exports = app => {
|
|
||||||
const sessionConfig = {
|
|
||||||
key: "budi:sess" /** (string) cookie key (default is koa:sess) */,
|
|
||||||
/** (number || 'session') maxAge in ms (default is 1 days) */
|
|
||||||
/** 'session' will result in a cookie that expires when session/browser is closed */
|
|
||||||
/** Warning: If a session cookie is stolen, this cookie will never expire */
|
|
||||||
maxAge: 86400000,
|
|
||||||
autoCommit: true /** (boolean) automatically commit headers (default true) */,
|
|
||||||
overwrite: true /** (boolean) can overwrite or not (default true) */,
|
|
||||||
httpOnly: true /** (boolean) httpOnly or not (default true) */,
|
|
||||||
signed: true /** (boolean) signed or not (default true) */,
|
|
||||||
rolling: false /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */,
|
|
||||||
renew: false /** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/,
|
|
||||||
store: {
|
|
||||||
get: async key => ({ key }),
|
|
||||||
set: async key => ({ key }),
|
|
||||||
destroy: async () => ({}),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return session(sessionConfig, app)
|
|
||||||
}
|
|
Loading…
Reference in New Issue