-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get config in server mode (#175)
* chore: move test * feat: read function config
- Loading branch information
1 parent
2ab8760
commit ea47d4e
Showing
4 changed files
with
86 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { join } from 'path' | ||
|
||
import getPort from 'get-port' | ||
import fetch from 'node-fetch' | ||
import { test, expect } from 'vitest' | ||
|
||
import { fixturesDir } from '../../test/util.js' | ||
import { serve } from '../index.js' | ||
|
||
test('Starts a server and serves requests for edge functions', async () => { | ||
const port = await getPort() | ||
const server = await serve({ | ||
port, | ||
}) | ||
const functionPath = join(fixturesDir, 'serve_test', 'echo_env.ts') | ||
|
||
const functions = [ | ||
{ | ||
name: 'echo_env', | ||
path: functionPath, | ||
}, | ||
] | ||
const options = { | ||
getFunctionsConfig: true, | ||
} | ||
const { functionsConfig, graph, success } = await server( | ||
functions, | ||
{ | ||
very_secret_secret: 'i love netlify', | ||
}, | ||
options, | ||
) | ||
expect(success).toBe(true) | ||
|
||
expect(functionsConfig).toEqual([{ path: '/my-function' }]) | ||
|
||
const graphEntry = graph?.modules.some( | ||
// @ts-expect-error TODO: Module graph is currently not typed | ||
({ kind, mediaType, local }) => kind === 'esm' && mediaType === 'TypeScript' && local === functionPath, | ||
) | ||
expect(graphEntry).toBe(true) | ||
|
||
const response = await fetch(`http://0.0.0.0:${port}/foo`, { | ||
headers: { | ||
'x-deno-functions': 'echo_env', | ||
'x-deno-pass': 'passthrough', | ||
'X-NF-Request-ID': 'foo', | ||
}, | ||
}) | ||
expect(response.status).toBe(200) | ||
|
||
const body = (await response.json()) as Record<string, string> | ||
expect(body.very_secret_secret).toBe('i love netlify') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
import { Config } from 'https://edge.netlify.com' | ||
|
||
export default async () => new Response(JSON.stringify(Deno.env.toObject())) | ||
|
||
export const config: Config = () => ({ | ||
path: '/my-function', | ||
}) |