Skip to content

Commit

Permalink
Adds js-app module that consumes the jsMain adapter from kmp module (k…
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoengenheiro committed Mar 15, 2024
1 parent 6b088f9 commit 95a3300
Show file tree
Hide file tree
Showing 29 changed files with 895 additions and 71 deletions.
5 changes: 2 additions & 3 deletions js-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ repositories {

dependencies {
implementation(kotlin("stdlib-js"))
// Install npm dependencies
implementation(npm("randomstring", "1.3.0"))
implementation(npm("is-sorted", "1.0.5"))
// TODO: necessary to access adapter in jsMain?
implementation(project(":kmp"))
}

kotlin {
Expand Down
40 changes: 40 additions & 0 deletions js-app/src/main/js/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
`use strict`

import {Adapter} from '../../../../build/js/packages/kresil-experiments-kmp/kotlin/kresil-experiments-kmp.mjs'
import express from 'express'

const app = express()
const port = 8080
const adapterInstance = Adapter.getInstance();

app.get('/add', (req, res) => {
adapterInstance.addBooks()
res.send('Hardcoded books added successfully')
})

app.get('/books', (req, res) => {
const books = adapterInstance.getBooks()
res.send(books)
})

// Route to handle clearing all books via DELETE request
app.get('/clear', (req, res) => {
adapterInstance.clearBooks()
res.send('All books cleared successfully');
});

app.get('/platform', (req, res) => {
const platform = adapterInstance.getPlatform()
res.send(platform)
})

// will never succeed
app.get('/ignore', (req, res) => {
const result = adapterInstance.ignored()
res.send(result)
})

// Start the server
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`)
})
Loading

0 comments on commit 95a3300

Please sign in to comment.