Skip to content
This repository was archived by the owner on Apr 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import express from 'express';
import { get, update } from '@reshuffle/db';
import { defaultHandler } from '@reshuffle/server-function';
import { authHandler } from '@reshuffle/passport';
import { initialData } from './constants';
import { editorPrefix } from './backend';

const app = express();
const devDBAdmin = require('@reshuffle/db-admin');
app.use('/dev/db-admin', express.json(), devDBAdmin.devDBAdminHandler);

/**GrapesJS Storage Manager Endpoints */
const editorPrefix = 'editor';

app.all('/store', express.json(), async function(req, res) {
const editorData = req.body;
Expand All @@ -19,7 +20,7 @@ app.all('/store', express.json(), async function(req, res) {
});

app.all('/load', async function(req, res) {
const result = await get(editorPrefix);
const result = (await get(editorPrefix)) || initialData;
res.json(result);
});

Expand Down
5 changes: 3 additions & 2 deletions backend/backend.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { get, update } from '@reshuffle/db';
const editorPrefix = 'editor';
import { initialData } from './constants';
export const editorPrefix = 'editor';

/**
* Get html, css, js fields from data that was sent from GrapesJs
*/
/* @expose */
export async function getHtmlFields() {
try {
const { html, css, js } = await get(editorPrefix);
const { html, css, js } = (await get(editorPrefix)) || initialData;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the code is repeating between backend/backend.js and backend/_handler.js - can it be extracted into a single location (e.g. so we don't define editorPrefix twice).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I exported the editorPrefix and importing in handler - hope this is what you meant :)

return { html: html, css: css, js: js };
} catch (err) {
console.log('error on getHtmlFields backend', err);
Expand Down
Loading