-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
createServerRunner.ts
38 lines (34 loc) · 1.33 KB
/
createServerRunner.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ResourcesConfig } from 'aws-amplify';
import { parseAmplifyConfig } from '@aws-amplify/core/internals/utils';
import { createRunWithAmplifyServerContext } from './utils';
import { NextServer } from './types';
/**
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
*
* @remarks
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
* your codebase.
*
* @param input The input used to create the `runWithAmplifyServerContext` function.
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
* created.
* @returns An object that contains the `runWithAmplifyServerContext` function.
*
* @example
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
* import config from './amplifyconfiguration.json';
*
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
*/
export const createServerRunner: NextServer.CreateServerRunner = ({
config,
}) => {
const amplifyConfig = parseAmplifyConfig(config);
return {
runWithAmplifyServerContext: createRunWithAmplifyServerContext({
config: amplifyConfig,
}),
};
};