./src/api.js annotated source

Back to index

        

This file defines the few Codeframe-internal API endpoints

2
3const {store} = require('./models.js');
4

This is the object that will contain all API methods for frames.

6const api = {
7    frame: {},
8}
9

frame.get allows to get a Codeframe file, given a hash

11api.frame.get = params => {
12    return store.getFromFS(params.frameHash);
13}
14

frame.post lets us create a new frame, and returns the hash generated.

16api.frame.post = async (_params, _query, body) => {
17    const frameHash = await store.create(body);
18    return frameHash;
19}
20

frame.getPage renders a full Codeframe page from two hashes, one for each of HTML and JS files. This is the "preview" page.

23api.frame.getPage = async params => {
24    const htmlFrame = await store.getFromFS(params.htmlFrameHash);
25    const jsFrame = await store.getFromFS(params.jsFrameHash);
26    return `<!DOCTYPE html>
27<html>
28    <head>
29        <meta charset="utf-8"/>
30        <meta name="viewport" content="width=device-width,initial-scale=1"/>
31        <title>Live Frame | Codeframe</title>
32    </head>
33    <body>
34        ${htmlFrame}
35        <script src="https://unpkg.com/torus-dom/dist/index.min.js"></script>
36        <script>${jsFrame}</script>
37    </body>
38</html>`;
39}
40
41module.exports = api;
42