A convenience package that provides Photon with automatic fallback functionality for quick prototyping and development.
The runtime package is designed to make getting started with Photon as simple as possible by:
- Automatic fallback: Provides a default minimal server when no server entry is specified
- Zero configuration: Works out of the box without any setup
- Development friendly: Perfect for prototyping and quick experiments
- Production ready: Can be used in production with proper configuration
npm install @photonjs/runtime
# or
pnpm add @photonjs/runtime
# or
yarn add @photonjs/runtimeThe simplest way to get started with Photon:
// vite.config.ts
import { photon } from '@photonjs/runtime/vite'
export default {
plugins: [
photon()
]
}That's it! The runtime package will automatically:
- Create a fallback Hono server if no server entry is provided
- Apply any universal middlewares you've defined
- Set up the development server with HMR
When no server entry is specified, the runtime package creates a default server equivalent to:
// Automatically generated fallback
import { apply, serve } from '@photonjs/hono'
import { Hono } from 'hono'
function startServer() {
const app = new Hono()
apply(app) // Applies your universal middlewares
return serve(app)
}
export default startServer()You can still provide custom configuration while using the runtime package:
// vite.config.ts
import { photon } from '@photonjs/runtime/vite'
export default {
plugins: [
photon({
entries: {
'api/users': './src/api/users.ts',
'middleware/auth': './src/middleware/auth.ts'
}
})
]
}If you want to use your own server entry, simply specify it:
// vite.config.ts
import { photon } from '@photonjs/runtime/vite'
export default {
plugins: [
photon({
server: './src/my-server.ts' // This overrides the fallback
})
]
}See the examples directory for complete working examples.
MIT