diff --git a/adminforth/commands/createApp/templates/api.ts.hbs b/adminforth/commands/createApp/templates/api.ts.hbs new file mode 100644 index 00000000..68d43806 --- /dev/null +++ b/adminforth/commands/createApp/templates/api.ts.hbs @@ -0,0 +1,10 @@ +import { Express } from "express"; +import { IAdminForth } from "adminforth"; + +export function initApi(app: Express, admin: IAdminForth) { + app.get(`${admin.config.baseUrl}/api/hello/`, + (req, res) => { + res.json({ message: "Hello from AdminForth API!" }); + } + ); +} \ No newline at end of file diff --git a/adminforth/commands/createApp/templates/index.ts.hbs b/adminforth/commands/createApp/templates/index.ts.hbs index 18398ca2..e299f226 100644 --- a/adminforth/commands/createApp/templates/index.ts.hbs +++ b/adminforth/commands/createApp/templates/index.ts.hbs @@ -4,7 +4,8 @@ import usersResource from "./resources/adminuser.js"; import { fileURLToPath } from 'url'; import path from 'path'; import { Filters } from 'adminforth'; - +import { initApi } from './api.js'; + const ADMIN_BASE_URL = ''; export const admin = new AdminForth({ @@ -69,6 +70,8 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) { const app = express(); app.use(express.json()); + initApi(app, admin); + const port = 3500; admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => { diff --git a/adminforth/commands/createApp/utils.js b/adminforth/commands/createApp/utils.js index c3cffee1..76b955c3 100644 --- a/adminforth/commands/createApp/utils.js +++ b/adminforth/commands/createApp/utils.js @@ -235,6 +235,11 @@ async function writeTemplateFiles(dirname, cwd, options) { dest: 'index.ts', data: { appName }, }, + { + src: 'api.ts.hbs', + dest: 'api.ts', + data: {}, + }, { src: '.gitignore.hbs', dest: '.gitignore',