Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.05 KB

adding-edgespec-to-existing-project.md

File metadata and controls

52 lines (40 loc) · 1.05 KB

Adding EdgeSpec to an existing project

  1. npm add edgespec -D
  2. Add .edgespec to your .gitignore.
  3. Create edgespec.config.ts at your project root:
import { defineConfig } from "edgespec"

export default defineConfig({
  // This an example, adjust as needed
  routesDirectory: "./src/api",
})
  1. Create with-edge-spec.ts:
import { createWithEdgeSpec } from "edgespec"

export const withRouteSpec = createWithEdgeSpec({
  apiName: "An Example API",
  productionServerUrl: "https://example.com",
  beforeAuthMiddleware: [],
  authMiddleware: {},
})
  1. Create a test API route in the directory you defined in edgespec.config.ts:
// src/api/hello-world.ts
import { withRouteSpec } from "../with-edge-spec"

export default withRouteSpec({
  methods: ["GET"],
})(() => {
  return new Response("Hello, world!")
})
  1. Add a script to your package.json:
{
  "scripts": {
    "dev": "edgespec dev"
  }
}
  1. Run npm run dev and visit http://localhost:3000/hello-world to see your API route!