Skip to content

Commit

Permalink
Add full Bryntum Scheduiling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomczoink committed Jan 5, 2024
0 parents commit 47546a4
Show file tree
Hide file tree
Showing 23 changed files with 6,633 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .api/configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

import express from "express";

// ViteServerHook
// @WARNING: Please don't include the VITE TYPES here, because it has a problem when you build the project
export const viteServerBefore = (server, viteServer) => {
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
};

// @WARNING: Please don't include the VITE TYPES here, because it has a problem when you build the project
export const viteServerAfter = (server, viteServer) => {
server.use((error, req, res, next) => {
if (error instanceof Error) {
return res.status(403).json({ error: error.message });
}
next(error);
});
};

// ServerHook
export const serverBefore = (server) => {
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
};

export const serverAfter = (server) => {
server.use((error, req, res, next) => {
if (error instanceof Error) {
return res.status(403).json({ error: error.message });
}
next(error);
});
};

// HandlerHook
export const handlerBefore = (handler) => {
};

export const handlerAfter = (server) => {
};

// CallbackHook
export const callbackBefore = (callback, route) => {
return callback;
};

// StatusHook
export const serverListening = (server) => {

};

export const serverError = (server, error) => {

};
26 changes: 26 additions & 0 deletions .api/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import express from "express";
import { applyRouters } from "@api/routers";
import * as configure from "@api/configure";

export const handler = express();

configure.handlerBefore?.(handler);

applyRouters(
(props) => {
const { method, route, path, cb } = props;
if (handler[method]) {
if(Array.isArray(cb)) {
handler[method](route, ...cb);
} else {
handler[method](route, cb);
}
} else {
console.log("Not Support", method, "for", route, "in", handler);
}
}
);

configure.handlerAfter?.(handler);

123 changes: 123 additions & 0 deletions .api/routers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

// Imports
import * as _0_0 from "//Users/tomcamp/Documents/GitHub/bryntum-ably-scheduler/byrntum-ably-demo/src/api/ably/token.js";
import * as _0_1 from "//Users/tomcamp/Documents/GitHub/bryntum-ably-scheduler/byrntum-ably-demo/src/api/state.js";
import * as configure from "@api/configure";

export const routeBase = "/api";

const internal = [
_0_0.default && {
source : "src/api/ably/token.js?fn=default",
method : "use",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.default,
},
_0_0.GET && {
source : "src/api/ably/token.js?fn=GET",
method : "get",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.GET,
},
_0_0.PUT && {
source : "src/api/ably/token.js?fn=PUT",
method : "put",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.PUT,
},
_0_0.POST && {
source : "src/api/ably/token.js?fn=POST",
method : "post",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.POST,
},
_0_0.PATCH && {
source : "src/api/ably/token.js?fn=PATCH",
method : "patch",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.PATCH,
},
_0_0.DELETE && {
source : "src/api/ably/token.js?fn=DELETE",
method : "delete",
route : "/ably/token",
path : "/api/ably/token",
url : "/api/ably/token",
cb : _0_0.DELETE,
},
_0_1.default && {
source : "src/api/state.js?fn=default",
method : "use",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.default,
},
_0_1.GET && {
source : "src/api/state.js?fn=GET",
method : "get",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.GET,
},
_0_1.PUT && {
source : "src/api/state.js?fn=PUT",
method : "put",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.PUT,
},
_0_1.POST && {
source : "src/api/state.js?fn=POST",
method : "post",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.POST,
},
_0_1.PATCH && {
source : "src/api/state.js?fn=PATCH",
method : "patch",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.PATCH,
},
_0_1.DELETE && {
source : "src/api/state.js?fn=DELETE",
method : "delete",
route : "/state",
path : "/api/state",
url : "/api/state",
cb : _0_1.DELETE,
}
].filter(it => it);

export const routers = internal.map((it) => {
const { method, path, route, url, source } = it;
return { method, url, path, route, source };
});

export const endpoints = internal.map(
(it) => it.method?.toUpperCase() + "\t" + it.url
);

export const applyRouters = (applyRouter) => {
internal.forEach((it) => {
it.cb = configure.callbackBefore?.(it.cb, it) || it.cb;
applyRouter(it);
});
};

21 changes: 21 additions & 0 deletions .api/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import { handler } from "@api/handler";
import { endpoints } from "@api/routers";
import * as configure from "@api/configure";
import express from "express";


const server = express();
configure.serverBefore?.(server);
const { PORT = 3000, PUBLIC_DIR = "import.meta.env.PUBLIC_DIR" } = process.env;
server.use("import.meta.env.BASE", express.static(PUBLIC_DIR));
server.use("import.meta.env.BASE_API", handler);
configure.serverAfter?.(server);
server.on("error", (error) => {
console.error(`Error at http://localhost:${PORT}import.meta.env.BASE`, error);
configure.serverError?.(server, error);
});
server.listen(PORT, () => {
console.log(`Ready at http://localhost:${PORT}import.meta.env.BASE`);
configure.serverListening?.(server, endpoints);
});
23 changes: 23 additions & 0 deletions .api/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

declare module "@api/handler" {
import { ServerHandler } from "vite-plugin-api-routes/model";
export const handler: ServerHandler;
}

declare module "@api/routers" {
import { ApplyRouters, RouteInfo } from "vite-plugin-api-routes/model";
export const routeBase: string;
export const routers: RouteInfo[];
export const endpoints: string[];
export const applyRouters: ApplyRouters;
}

declare module "@api/configure" {
export {
ViteServerHook,
ServerHook,
HandlerHook,
CallbackHook,
StatusHook,
} from "vite-plugin-api-routes/model";
}
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_ABLY_API_KEY="[YOUR_ABLY_API_KEY]"
20 changes: 20 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Loading

0 comments on commit 47546a4

Please sign in to comment.