-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNuxtSite.ts
More file actions
97 lines (88 loc) · 2.53 KB
/
NuxtSite.ts
File metadata and controls
97 lines (88 loc) · 2.53 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import fs from "fs";
import path from "path";
import { Function as CdkFunction } from "aws-cdk-lib/aws-lambda";
import { SsrSite } from 'sst/constructs/SsrSite.js';
import { SsrFunction } from "sst/constructs/SsrFunction.js";
import { EdgeFunction } from "sst/constructs/EdgeFunction.js";
/**
* The `NuxtSite` construct is a higher level CDK construct that makes it easy to create a Nuxt app.
* @example
* Deploys a Nuxt app in the `my-nuxt-app` directory.
*
* ```js
* new NuxtSite(stack, "web", {
* path: "my-Nuxt-app/",
* });
* ```
*/
export class NuxtSite extends SsrSite {
protected initBuildConfig() {
return {
typesPath: "./",
serverBuildOutputFile: ".output/server/index.mjs",
clientBuildOutputDir: ".output/public",
clientBuildVersionedSubDir: "_nuxt",
};
}
protected validateBuildOutput() {
const serverDir = path.join(this.props.path, ".output/server");
const clientDir = path.join(this.props.path, ".output/public");
if (!fs.existsSync(serverDir) || !fs.existsSync(clientDir)) {
throw new Error(`Build output inside ".output/" does not contain the "server" and "public" folders. Make sure Server-side Rendering (SSR) is enabled in your Nuxt app. If you are looking to deploy the Nuxt app as a static site, please use the StaticSite construct — https://docs.sst.dev/constructs/StaticSite`);
}
super.validateBuildOutput();
}
protected createFunctionForRegional(): CdkFunction {
const {
runtime,
timeout,
memorySize,
permissions,
environment,
nodejs,
bind,
cdk,
} = this.props;
const ssrFn = new SsrFunction(this, `ServerFunction`, {
description: "Server handler for Nuxt",
handler: path.join(this.props.path, ".output", "server", "index.handler"),
runtime,
memorySize,
timeout,
nodejs: {
format: "esm",
...nodejs,
},
bind,
environment,
permissions,
...cdk?.server,
});
return ssrFn.function;
}
protected createFunctionForEdge(): EdgeFunction {
const {
runtime,
timeout,
memorySize,
bind,
permissions,
environment,
nodejs,
} = this.props;
return new EdgeFunction(this, `Server`, {
scopeOverride: this,
handler: path.join(this.props.path, ".output", "server", "index.handler"),
runtime,
timeout,
memorySize,
bind,
environment,
permissions,
nodejs: {
format: "esm",
...nodejs,
},
});
}
}