eddev 0.2.0-beta.23 → 0.2.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/get-webpack-config.js +5 -1
- package/build/serverless/create-next-app.js +22 -8
- package/build/workers/codegen-worker-script.js +2 -0
- package/dev-ui/theme.d.ts +0 -1
- package/dynamic/dynamic-component.d.ts +0 -1
- package/entry/Root.d.ts +3 -1
- package/entry/Root.js +12 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/rpc-client.d.ts +3 -0
- package/hooks/rpc-client.js +15 -0
- package/hooks/useRPC.d.ts +4 -0
- package/hooks/useRPC.js +16 -0
- package/package.json +1 -1
- package/serverless/create-rpc-client.d.ts +0 -1
- package/serverless/define-rpc-router.d.ts +3 -1
- package/serverless/define-rpc-router.js +9 -3
- package/serverless/index.d.ts +0 -1
- package/serverless/index.js +0 -1
- package/serverless/rpc-client.d.ts +3 -0
- package/serverless/rpc-client.js +15 -0
- package/serverless-template/_utils/PageMeta.tsx +3 -2
- package/serverless-template/next.config.js +6 -1
- package/serverless-template/package.json +3 -1
- package/serverless-template/pages/_app.tsx +15 -2
- package/serverless-template/pages/api/trpc/[...trpc].ts +31 -0
- package/style/createStitches.d.ts +0 -1
- package/serverless-template/pages/api/hello.ts +0 -10
|
@@ -74,13 +74,14 @@ var mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin
|
|
|
74
74
|
var autoprefixer_1 = __importDefault(require("autoprefixer"));
|
|
75
75
|
// Custom Babel plugins
|
|
76
76
|
var plugin_name_defined_components_1 = __importDefault(require("./babel/plugin-name-defined-components"));
|
|
77
|
+
var fs_1 = require("fs");
|
|
77
78
|
var manifest_blocks_1 = require("./manifests/manifest-blocks");
|
|
78
79
|
var manifest_fields_1 = require("./manifests/manifest-fields");
|
|
79
80
|
var manifest_views_1 = require("./manifests/manifest-views");
|
|
80
81
|
var get_config_1 = require("../config/get-config");
|
|
81
82
|
function getWebpackConfig(opts) {
|
|
82
83
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var compiling, config, ALIAS, ENTRY, PLUGINS, RULES, DEFINES, VIRTUAL_MODULES, EXTERNALS, virtualModules, isServerless, isBrowser, isSSR, isDev, entryDir, distSuffix, outputFolder, loadableManifestFile, writeVirtualModule, manifestLoaders, buildID;
|
|
84
|
+
var compiling, config, ALIAS, ENTRY, PLUGINS, RULES, DEFINES, VIRTUAL_MODULES, EXTERNALS, virtualModules, isServerless, isBrowser, isSSR, isDev, entryDir, distSuffix, outputFolder, loadableManifestFile, writeVirtualModule, manifestLoaders, rpcExists, buildID;
|
|
84
85
|
return __generator(this, function (_a) {
|
|
85
86
|
switch (_a.label) {
|
|
86
87
|
case 0:
|
|
@@ -333,6 +334,9 @@ function getWebpackConfig(opts) {
|
|
|
333
334
|
}
|
|
334
335
|
DEFINES["process.devUI"] = config.devUI === "enabled";
|
|
335
336
|
DEFINES["process.serverlessEndpoint"] = "window.SERVERLESS_ENDPOINT";
|
|
337
|
+
rpcExists = (0, fs_1.existsSync)(path_1.default.join(opts.baseDirectory, "api/_rpc.ts")) ||
|
|
338
|
+
(0, fs_1.existsSync)(path_1.default.join(opts.baseDirectory, "api/_rpc/index.ts"));
|
|
339
|
+
DEFINES["process.rpcEnabled"] = rpcExists ? "true" : "false";
|
|
336
340
|
if (isBrowser) {
|
|
337
341
|
DEFINES["process.env.themePath"] = "window.THEME_PATH || ".concat(DEFINES["process.env.themePath"]);
|
|
338
342
|
}
|
|
@@ -129,6 +129,7 @@ function createNextApp(opts) {
|
|
|
129
129
|
"types.graphql.ts",
|
|
130
130
|
"types.views.ts",
|
|
131
131
|
"types.blocks.ts",
|
|
132
|
+
"types.api.ts",
|
|
132
133
|
"utils/**/*",
|
|
133
134
|
"ed.config.json",
|
|
134
135
|
])
|
|
@@ -167,13 +168,23 @@ function createNextApp(opts) {
|
|
|
167
168
|
_b.label = 14;
|
|
168
169
|
case 14:
|
|
169
170
|
// Sync favicon
|
|
170
|
-
return [4 /*yield*/, copyFiles((0, path_1.join)(opts.baseDirectory), (0, path_1.join)(serverlessDirectory, "public/"), ["favicon.ico"])
|
|
171
|
+
return [4 /*yield*/, copyFiles((0, path_1.join)(opts.baseDirectory), (0, path_1.join)(serverlessDirectory, "public/"), ["favicon.ico"])
|
|
172
|
+
// Write APIs proxy code
|
|
173
|
+
];
|
|
171
174
|
case 15:
|
|
172
175
|
// Sync favicon
|
|
173
176
|
_b.sent();
|
|
174
|
-
|
|
177
|
+
// Write APIs proxy code
|
|
178
|
+
return [4 /*yield*/, writeAPIProxies((0, path_1.join)(opts.baseDirectory, "api"), (0, path_1.join)(serverlessDirectory, "pages/api"))
|
|
179
|
+
// Remove pages/api/trpc directory if no _rpc is found
|
|
180
|
+
];
|
|
175
181
|
case 16:
|
|
182
|
+
// Write APIs proxy code
|
|
176
183
|
_b.sent();
|
|
184
|
+
// Remove pages/api/trpc directory if no _rpc is found
|
|
185
|
+
if (!(0, fs_1.existsSync)((0, path_1.join)(opts.baseDirectory, "api/_rpc")) || !(0, fs_1.existsSync)((0, path_1.join)(opts.baseDirectory, "api/_rpc.ts"))) {
|
|
186
|
+
(0, fs_extra_1.removeSync)((0, path_1.join)(serverlessDirectory, "pages/api/trpc"));
|
|
187
|
+
}
|
|
177
188
|
_b.label = 17;
|
|
178
189
|
case 17:
|
|
179
190
|
if (!!isVercel) return [3 /*break*/, 19];
|
|
@@ -309,7 +320,8 @@ function writeAPIProxies(sourceFolder, targetFolder) {
|
|
|
309
320
|
return [4 /*yield*/, Promise.all(files.map(function (file) {
|
|
310
321
|
var name = file.replace(sourceFolder, "");
|
|
311
322
|
var outputPath = (0, path_1.join)(targetFolder, name);
|
|
312
|
-
|
|
323
|
+
if (name.includes("_rpc"))
|
|
324
|
+
return;
|
|
313
325
|
return (0, promises_1.writeFile)(outputPath, "import handler from \"".concat(file, "\"; export default handler;"));
|
|
314
326
|
}))];
|
|
315
327
|
case 2:
|
|
@@ -322,7 +334,9 @@ function writeAPIProxies(sourceFolder, targetFolder) {
|
|
|
322
334
|
function syncAPIProxies(sourceFolder, targetFolder) {
|
|
323
335
|
return __awaiter(this, void 0, void 0, function () {
|
|
324
336
|
return __generator(this, function (_a) {
|
|
325
|
-
return [2 /*return*/, syncFiles(sourceFolder, targetFolder, ["**/*.{tsx,ts,js}"], function (inputPath
|
|
337
|
+
return [2 /*return*/, syncFiles(sourceFolder, targetFolder, ["**/*.{tsx,ts,js}"], function (inputPath) {
|
|
338
|
+
if (inputPath.includes("_rpc"))
|
|
339
|
+
return null;
|
|
326
340
|
return "import handler from \"".concat(inputPath.replace(/\.(ts|js)x?$/, ""), "\"; export default handler;");
|
|
327
341
|
})];
|
|
328
342
|
});
|
|
@@ -336,12 +350,9 @@ function copyFiles(sourceFolder, targetFolder, patterns) {
|
|
|
336
350
|
case 0: return [4 /*yield*/, Promise.all(patterns.map(function (pattern) { return (0, glob_promise_1.default)((0, path_1.resolve)(sourceFolder, pattern)); }))];
|
|
337
351
|
case 1:
|
|
338
352
|
files = (_a.sent()).flat();
|
|
339
|
-
console.log("Files are", files);
|
|
340
353
|
// Replace sourceFolder in each path, and copy to target folder
|
|
341
354
|
return [4 /*yield*/, Promise.all(files.map(function (file) {
|
|
342
|
-
console.log("Copying", file, file.replace(sourceFolder, targetFolder));
|
|
343
355
|
var stat = (0, fs_1.statSync)(file);
|
|
344
|
-
console.log("File exists", file);
|
|
345
356
|
if (!stat.isDirectory()) {
|
|
346
357
|
return (0, fs_extra_1.copy)(file, file.replace(sourceFolder, targetFolder));
|
|
347
358
|
}
|
|
@@ -371,7 +382,10 @@ function syncFiles(sourceFolder, targetFolder, patterns, proxy) {
|
|
|
371
382
|
})
|
|
372
383
|
.on("add", function (path) {
|
|
373
384
|
if (proxy) {
|
|
374
|
-
|
|
385
|
+
var output = proxy((0, path_1.relative)(targetFolder, (0, path_1.join)(sourceFolder, path)), (0, path_1.join)(targetFolder, path));
|
|
386
|
+
if (typeof output === "string") {
|
|
387
|
+
(0, promises_1.writeFile)((0, path_1.join)(targetFolder, path), output);
|
|
388
|
+
}
|
|
375
389
|
}
|
|
376
390
|
else {
|
|
377
391
|
(0, fs_extra_1.copy)((0, path_1.join)(sourceFolder, path), (0, path_1.join)(targetFolder, path));
|
|
@@ -162,6 +162,8 @@ function beginWork(opts) {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}); };
|
|
165
|
+
// Create RPC/API types
|
|
166
|
+
(0, promises_1.writeFile)(Path.join(opts.baseDirectory, "types.api.ts"), "\n import type { router, createContext } from \"./api/_rpc\"\n import { createReactQueryHooks } from \"@trpc/react\"\n export {}\n \n const createQueryHooks = () => createReactQueryHooks<typeof router>()\n \n declare global {\n type RPCUse = ReturnType<typeof createQueryHooks>\n type RPCRouter = typeof router\n type RPCContextType = Awaited<ReturnType<typeof createContext>>\n type RPCClient = ReturnType<RPCUse[\"createClient\"]>\n type RPCUseQuery = RPCUse[\"useQuery\"]\n type RPCUseMutation = RPCUse[\"useMutation\"]\n type RPCUseInfiniteQuery = RPCUse[\"useInfiniteQuery\"]\n } \n ");
|
|
165
167
|
regenerate = debounce(100, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
166
168
|
var startTime, hasChanged, err_1, documentSets, parseErrors, _loop_1, _a, _b, _i, key, generates, errors, _c, _d, _e, file, base, config, output, err_2;
|
|
167
169
|
var _this = this;
|
package/dev-ui/theme.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const styled: <Type extends import("react").ComponentType<any> | keyof JSX.IntrinsicElements | import("@stitches/react/types/util").Function, Composers extends (string | import("react").ComponentType<any> | import("@stitches/react/types/util").Function | {
|
|
3
2
|
[name: string]: unknown;
|
|
4
3
|
})[], CSS = import("@stitches/react/types/css-util").CSS<{}, {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const dynamic: {
|
|
3
2
|
<Props, Module = import("@loadable/component").DefaultComponent<Props>>(loadFn: (props: Props) => Promise<Module>, options: import("@loadable/component").OptionsWithResolver<Props, Module>): import("@loadable/component").LoadableComponent<Props>;
|
|
4
3
|
<Props_1>(loadFn: (props: Props_1) => Promise<import("@loadable/component").DefaultComponent<Props_1>>, options?: import("@loadable/component").OptionsWithoutResolver<Props_1> | undefined): import("@loadable/component").LoadableComponent<Props_1>;
|
package/entry/Root.d.ts
CHANGED
package/entry/Root.js
CHANGED
|
@@ -36,6 +36,7 @@ var views_1 = __importStar(require("@manifest/views"));
|
|
|
36
36
|
var react_1 = require("react");
|
|
37
37
|
var routing_1 = require("../routing");
|
|
38
38
|
var loader_1 = require("../dev-ui/loader");
|
|
39
|
+
var next_1 = require("@trpc/next");
|
|
39
40
|
function Root() {
|
|
40
41
|
var route = (0, routing_1.useRoute)();
|
|
41
42
|
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [process.devUI && (0, jsx_runtime_1.jsx)(loader_1.DevUILoader, {}, void 0), (0, jsx_runtime_1.jsx)(views_1.App, { children: (0, jsx_runtime_1.jsx)(routing_1.Switch, { children: Object.entries(views_1.default).map(function (_a) {
|
|
@@ -44,4 +45,14 @@ function Root() {
|
|
|
44
45
|
return ((0, jsx_runtime_1.jsx)(routing_1.Route, __assign({ match: function (route) { var _a; return ((_a = route.data) === null || _a === void 0 ? void 0 : _a.view) === name; } }, { children: (0, jsx_runtime_1.jsx)(Component, __assign({}, (_c = (_b = route.data) === null || _b === void 0 ? void 0 : _b.viewData) === null || _c === void 0 ? void 0 : _c.data), void 0) }), name));
|
|
45
46
|
}) }, void 0) }, void 0)] }, void 0));
|
|
46
47
|
}
|
|
47
|
-
exports.default =
|
|
48
|
+
exports.default = process.rpcEnabled
|
|
49
|
+
? (0, next_1.withTRPC)({
|
|
50
|
+
config: function (_a) {
|
|
51
|
+
var ctx = _a.ctx;
|
|
52
|
+
return {
|
|
53
|
+
url: process.serverlessEndpoint + "api/trpc",
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
ssr: false,
|
|
57
|
+
})(Root)
|
|
58
|
+
: Root;
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
|
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./usePageLoad"), exports);
|
|
14
14
|
__exportStar(require("./useAppData"), exports);
|
|
15
|
+
__exportStar(require("./useRPC"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const useRPCQuery: <TPath extends string>(pathAndInput: [TPath, (null | undefined)?], opts?: import("@trpc/react").UseTRPCQueryOptions<TPath, RPCRouter, RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>> | undefined) => import("react-query").UseQueryResult<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>>;
|
|
2
|
+
export declare const useRPCMutation: <TPath_1 extends string>(path: TPath_1 | [TPath_1], opts?: import("@trpc/react").UseTRPCMutationOptions<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>, RPCRouter> | undefined) => import("react-query").UseMutationResult<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>, RPCRouter, unknown>;
|
|
3
|
+
export declare const rpcClient: import("@trpc/react").TRPCClient<RPCRouter>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpcClient = exports.useRPCMutation = exports.useRPCQuery = void 0;
|
|
4
|
+
var react_1 = require("@trpc/react");
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
var _a = (0, react_1.createReactQueryHooks)({
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
url: process.serverlessEndpoint + "/api/trpc",
|
|
9
|
+
}), useQuery = _a.useQuery, useMutation = _a.useMutation, createClient = _a.createClient;
|
|
10
|
+
exports.useRPCQuery = useQuery;
|
|
11
|
+
exports.useRPCMutation = useMutation;
|
|
12
|
+
exports.rpcClient = createClient({
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
url: process.serverlessEndpoint + "/api/trpc",
|
|
15
|
+
});
|
package/hooks/useRPC.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpcClient = exports.useRPCMutation = exports.useRPCQuery = void 0;
|
|
4
|
+
var react_1 = require("@trpc/react");
|
|
5
|
+
var trpc = (0, react_1.createReactQueryHooks)();
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
exports.useRPCQuery = trpc.useQuery;
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
exports.useRPCMutation = trpc.useQuery;
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
exports.useRPCMutation = trpc.useInfiniteQuery;
|
|
12
|
+
exports.rpcClient = trpc.createClient({
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
url: process.serverlessEndpoint + "/api/trpc",
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
});
|
package/package.json
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import * as trpc from "@trpc/server";
|
|
2
|
-
|
|
2
|
+
import * as trpcNext from "@trpc/server/adapters/next";
|
|
3
|
+
export declare function defineRPC<TCreator extends (base: ReturnType<typeof trpc.router>, z: typeof import("zod")) => any>(creator: TCreator): ReturnType<TCreator>;
|
|
4
|
+
export declare function defineRPCContextCreator<TCreator extends (opts: trpcNext.CreateNextContextOptions) => any>(creator: TCreator): TCreator;
|
|
@@ -19,9 +19,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.defineRPC = void 0;
|
|
22
|
+
exports.defineRPCContextCreator = exports.defineRPC = void 0;
|
|
23
23
|
var trpc = __importStar(require("@trpc/server"));
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
var z = __importStar(require("zod"));
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
function defineRPC(creator) {
|
|
27
|
+
return creator(trpc.router(), z);
|
|
26
28
|
}
|
|
27
29
|
exports.defineRPC = defineRPC;
|
|
30
|
+
function defineRPCContextCreator(creator) {
|
|
31
|
+
return creator;
|
|
32
|
+
}
|
|
33
|
+
exports.defineRPCContextCreator = defineRPCContextCreator;
|
package/serverless/index.d.ts
CHANGED
package/serverless/index.js
CHANGED
|
@@ -12,5 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./define-api"), exports);
|
|
14
14
|
__exportStar(require("./define-rpc-router"), exports);
|
|
15
|
-
__exportStar(require("./create-rpc-client"), exports);
|
|
16
15
|
__exportStar(require("./error-codes"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const useRPCQuery: <TPath extends string>(pathAndInput: [TPath, (null | undefined)?], opts?: import("@trpc/react").UseTRPCQueryOptions<TPath, RPCRouter, RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>> | undefined) => import("react-query").UseQueryResult<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>>;
|
|
2
|
+
export declare const useRPCMutation: <TPath_1 extends string>(path: TPath_1 | [TPath_1], opts?: import("@trpc/react").UseTRPCMutationOptions<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>, RPCRouter> | undefined) => import("react-query").UseMutationResult<RPCRouter, import("@trpc/react").TRPCClientErrorLike<RPCRouter>, RPCRouter, unknown>;
|
|
3
|
+
export declare const rpcClient: import("@trpc/react").TRPCClient<RPCRouter>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpcClient = exports.useRPCMutation = exports.useRPCQuery = void 0;
|
|
4
|
+
var react_1 = require("@trpc/react");
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
var _a = (0, react_1.createReactQueryHooks)({
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
url: process.serverlessEndpoint + "/api/trpc",
|
|
9
|
+
}), useQuery = _a.useQuery, useMutation = _a.useMutation, createClient = _a.createClient;
|
|
10
|
+
exports.useRPCQuery = useQuery;
|
|
11
|
+
exports.useRPCMutation = useMutation;
|
|
12
|
+
exports.rpcClient = createClient({
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
url: process.serverlessEndpoint + "/api/trpc",
|
|
15
|
+
});
|
|
@@ -10,7 +10,7 @@ export function PageMeta(props: Props) {
|
|
|
10
10
|
{props.title?.map((tag, i) => (
|
|
11
11
|
<title key={"title" + i}>{tag.__code}</title>
|
|
12
12
|
))}
|
|
13
|
-
{props.style?.map((tag, i) => {
|
|
13
|
+
{/* {props.style?.map((tag, i) => {
|
|
14
14
|
return (
|
|
15
15
|
<style
|
|
16
16
|
key={"style" + i}
|
|
@@ -31,11 +31,12 @@ export function PageMeta(props: Props) {
|
|
|
31
31
|
dangerouslySetInnerHTML={{ __html: tag.__code }}
|
|
32
32
|
/>
|
|
33
33
|
)
|
|
34
|
-
})}
|
|
34
|
+
})} */}
|
|
35
35
|
{props.meta?.map((tag, i) => {
|
|
36
36
|
return <meta key={"meta" + i} {...tag} />
|
|
37
37
|
})}
|
|
38
38
|
{props.link?.map((tag, i) => {
|
|
39
|
+
if (tag.rel === "stylesheet") return <Fragment key={"link" + i} />
|
|
39
40
|
return <link key={"link" + i} {...tag} />
|
|
40
41
|
})}
|
|
41
42
|
</Head>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const withTM = require("next-transpile-modules")
|
|
2
|
-
const { resolve } = require("path")
|
|
2
|
+
const { resolve, join } = require("path")
|
|
3
3
|
const { DefinePlugin } = require("webpack")
|
|
4
4
|
const settings = require("./ed.config.json")
|
|
5
5
|
const { getRepoName } = require("eddev/utils/getRepoName")
|
|
6
|
+
const { existsSync } = require("fs")
|
|
6
7
|
|
|
7
8
|
module.exports = (() => {
|
|
8
9
|
const cwd = process.cwd()
|
|
@@ -58,6 +59,10 @@ module.exports = (() => {
|
|
|
58
59
|
define.definitions["process.themePath"] = JSON.stringify(themePath)
|
|
59
60
|
define.definitions["process.devUI"] = settings.devUI === "enabled"
|
|
60
61
|
define.definitions["process.serverlessEndpoint"] = JSON.stringify("/")
|
|
62
|
+
|
|
63
|
+
const rpcExists =
|
|
64
|
+
existsSync(join(process.cwd(), "api/_rpc.ts")) || existsSync(join(process.cwd(), "api/_rpc/index.ts"))
|
|
65
|
+
define.definitions["process.rpcEnabled"] = rpcExists ? "true" : "false"
|
|
61
66
|
// config.plugins.push(
|
|
62
67
|
// new DefinePlugin({
|
|
63
68
|
// "process.serverless": "true",
|
|
@@ -7,8 +7,9 @@ import { useMemo } from "react"
|
|
|
7
7
|
import { useRouter } from "next/router"
|
|
8
8
|
import { DevUILoader } from "eddev/dev-ui/loader"
|
|
9
9
|
import { PageMeta } from "../_utils/PageMeta"
|
|
10
|
+
import { withTRPC } from "@trpc/next"
|
|
10
11
|
|
|
11
|
-
function
|
|
12
|
+
function Root({ Component, pageProps }: AppProps) {
|
|
12
13
|
if (!pageProps.appData) return <div />
|
|
13
14
|
|
|
14
15
|
const appData = useMemo(() => {
|
|
@@ -34,4 +35,16 @@ function MyApp({ Component, pageProps }: AppProps) {
|
|
|
34
35
|
</ServerlessAppDataProvider>
|
|
35
36
|
)
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
export default process.rpcEnabled
|
|
41
|
+
? withTRPC({
|
|
42
|
+
config({ ctx }) {
|
|
43
|
+
return {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
url: process.serverlessEndpoint + "api/trpc",
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
ssr: false,
|
|
49
|
+
})(Root)
|
|
50
|
+
: Root
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { router, createContext } from "../../../api/_rpc"
|
|
3
|
+
import * as trpcNext from "@trpc/server/adapters/next"
|
|
4
|
+
import type { NextApiRequest, NextApiResponse } from "next"
|
|
5
|
+
|
|
6
|
+
const handler = trpcNext.createNextApiHandler({
|
|
7
|
+
router: router,
|
|
8
|
+
createContext: createContext,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export default function (req: NextApiRequest, res: NextApiResponse) {
|
|
12
|
+
console.log("Req", req.method)
|
|
13
|
+
// if (req.method === "OPTIONS") {
|
|
14
|
+
const origin = req.headers.origin
|
|
15
|
+
if (origin) {
|
|
16
|
+
console.log(origin)
|
|
17
|
+
if (origin.match(/\.local$/)) {
|
|
18
|
+
res.setHeader("Access-Control-Allow-Origin", "*")
|
|
19
|
+
res.setHeader("Access-Control-Request-Method", "*")
|
|
20
|
+
res.setHeader("Access-Control-Request-Method", "OPTIONS, GET, POST")
|
|
21
|
+
res.setHeader("Access-Control-Allow-Headers", "*")
|
|
22
|
+
if (req.method === "OPTIONS") {
|
|
23
|
+
res.writeHead(200)
|
|
24
|
+
res.end()
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// }
|
|
30
|
+
return handler(req, res)
|
|
31
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
2
|
-
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
3
|
-
|
|
4
|
-
type Data = {
|
|
5
|
-
name: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default (req: NextApiRequest, res: NextApiResponse<Data>) => {
|
|
9
|
-
res.status(200).json({ name: 'John Doe' })
|
|
10
|
-
}
|