Skip to content

Commit

Permalink
feat: multi platform
Browse files Browse the repository at this point in the history
- Add support for multi support serverless functions
- Better dist folder to allow importing only needed files
- Move tests around
- Update documentation
  • Loading branch information
svedova committed Oct 18, 2023
1 parent 85aa19e commit 9dc95d2
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 150 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,49 @@ export const handler = serverless(
);
```

By default the above example will use a Stormkit handler for SSR. To use a different handler specify the secondary argument:
If you know beforehand the platform that is going to be deployed, you can import directly
the relevant handler:

```js
import serverless from "@stormkit/serverless/aws";

export const handler = serverless(
async (req: http.IncomingMessage, res: http.ServerResponse) => {
res.write("Hello from " + req.url);
res.end();
},
"stormkit:api"
);
```

## API Functions

If you're using [API functions](https://www.stormkit.io/docs/features/writing-api), and would like to
deploy to a custom environment you can use our middlewares:

```js
import api from "@stormkit/serverless/middlewares/express";
import express from "express";
import vite from "vite";

// Create Vite server in middleware mode and configure the app type as
// 'custom', disabling Vite's own HTML serving logic so parent server
// can take control
const vite = await createViteServer({
server: { middlewareMode: true },
appType: "custom",
});

// use vite's connect instance as middleware
// if you use your own express router (express.Router()), you should use router.use
app.use(vite.middlewares);

// Add support for a local environment API.
app.all(["/api", "/api/*"], apiMiddleware({
apiDir: "src/api",
moduleLoader: vite.ssrLoadModule
}));
```

## License

Made with 💛 Published under [MIT](./LICENSE).
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
verbose: false,
roots: ["tests/unit/", "src"],
roots: ["src"],
moduleNameMapper: {
"~(.*)$": "<rootDir>/src/$1",
},
Expand Down

0 comments on commit 9dc95d2

Please sign in to comment.