| 23 | import tags from './routes/tags' |
| 24 | |
| 25 | export async function initApi() { |
| 26 | // поскольку @elysiajs/node использует crossws, который работает только в ESM среде, |
| 27 | // то делаем хак с динамическим импортом |
| 28 | const { node } = await importEsm('@elysiajs/node') |
| 29 | |
| 30 | const app = new Elysia({ adapter: node() }) |
| 31 | const port = store.preferences.get('api.port') |
| 32 | |
| 33 | app |
| 34 | .use(cors({ origin: '*' })) |
| 35 | .use( |
| 36 | swagger({ |
| 37 | documentation: { |
| 38 | info: { |
| 39 | title: 'massCode API', |
| 40 | version: electronApp.getVersion(), |
| 41 | }, |
| 42 | }, |
| 43 | }), |
| 44 | ) |
| 45 | .use(captures) |
| 46 | .use(snippets) |
| 47 | .use(folders) |
| 48 | .use(system) |
| 49 | .use(tags) |
| 50 | .use(notesDashboard) |
| 51 | .use(notesGraph) |
| 52 | .use(notes) |
| 53 | .use(noteFolders) |
| 54 | .use(noteTags) |
| 55 | .use(internalLinks) |
| 56 | .use(httpFolders) |
| 57 | .use(httpRequests) |
| 58 | .use(httpEnvironments) |
| 59 | .use(httpHistory) |
| 60 | .use(httpImport) |
| 61 | .use(imports) |
| 62 | .listen(port) |
| 63 | |
| 64 | // eslint-disable-next-line no-console |
| 65 | console.log(`\nAPI started on port ${port}\n`) |
| 66 | } |