Move packages/apps back
This commit is contained in:
parent
6eaaf8e9be
commit
5535d6b575
348 changed files with 0 additions and 0 deletions
28
apps/metamigo-api/server/index.ts
Normal file
28
apps/metamigo-api/server/index.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import * as Metamigo from "common";
|
||||
import { defState } from "@digiresilience/montar";
|
||||
import Manifest from "./manifest";
|
||||
import config, { IAppConfig } from "../config";
|
||||
|
||||
export const deployment = async (
|
||||
config: IAppConfig,
|
||||
start = false
|
||||
): Promise<Metamigo.Server> => {
|
||||
// Build the manifest, which describes all the plugins needed for our application server
|
||||
const manifest = await Manifest.build(config);
|
||||
|
||||
// Create the server and optionally start it
|
||||
const server = Metamigo.deployment(manifest, config, start);
|
||||
|
||||
return server;
|
||||
};
|
||||
|
||||
export const stopDeployment = async (server: Metamigo.Server): Promise<void> => {
|
||||
return Metamigo.stopDeployment(server);
|
||||
};
|
||||
|
||||
const server = defState("server", {
|
||||
start: () => deployment(config, true),
|
||||
stop: () => stopDeployment(server),
|
||||
});
|
||||
|
||||
export default server;
|
||||
79
apps/metamigo-api/server/manifest.ts
Normal file
79
apps/metamigo-api/server/manifest.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import * as Glue from "@hapi/glue";
|
||||
import * as Metamigo from "common";
|
||||
import * as Blipp from "blipp";
|
||||
import HapiBasic from "@hapi/basic";
|
||||
import HapiJwt from "hapi-auth-jwt2";
|
||||
import HapiPostgraphile from "hapi-postgraphile";
|
||||
import { getPostGraphileOptions } from "db";
|
||||
import AppPlugin from "../app";
|
||||
import type { IAppConfig } from "../config";
|
||||
|
||||
const build = async (config: IAppConfig): Promise<Glue.Manifest> => {
|
||||
const { port, address } = config.server;
|
||||
const metamigoPlugins = Metamigo.defaultPlugins(config);
|
||||
return {
|
||||
server: {
|
||||
port,
|
||||
address,
|
||||
debug: false, // We use pino not the built-in hapi logger
|
||||
routes: {
|
||||
validate: {
|
||||
failAction: Metamigo.validatingFailAction,
|
||||
},
|
||||
},
|
||||
},
|
||||
register: {
|
||||
plugins: [
|
||||
// jwt plugin, required for our jwt auth plugin
|
||||
{ plugin: HapiJwt },
|
||||
|
||||
// Blipp prints the nicely formatted list of endpoints at app boot
|
||||
{ plugin: Blipp },
|
||||
|
||||
// load the metamigo base plugins
|
||||
...metamigoPlugins,
|
||||
|
||||
// basic authentication, required by hapi-nextauth
|
||||
{ plugin: HapiBasic },
|
||||
|
||||
// load our main app
|
||||
{
|
||||
plugin: AppPlugin,
|
||||
options: {
|
||||
config,
|
||||
},
|
||||
},
|
||||
// load Postgraphile
|
||||
{
|
||||
plugin: HapiPostgraphile,
|
||||
options: {
|
||||
route: {
|
||||
path: "/graphql",
|
||||
options: {
|
||||
auth: {
|
||||
strategies: ["nextauth-jwt"],
|
||||
mode: "optional",
|
||||
},
|
||||
},
|
||||
},
|
||||
pgConfig: config.postgraphile.authConnection,
|
||||
schemaName: "app_public",
|
||||
schemaOptions: {
|
||||
...getPostGraphileOptions(),
|
||||
jwtAudiences: [config.nextAuth.audience],
|
||||
jwtSecret: "",
|
||||
// unauthenticated users will hit the database with this role
|
||||
pgDefaultRole: "app_anonymous",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const Manifest = {
|
||||
build,
|
||||
};
|
||||
|
||||
export default Manifest;
|
||||
Loading…
Add table
Add a link
Reference in a new issue