Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
_BUILD_WEBSITE_URL=https://appwrite.io
_BUILD_WEBSITE_VERSION=1.6.x
_BUILD_WEBSITE_VERSION=cloud
_BUILD_GIT_URL=https://github.com/appwrite/website.git
_BUILD_GIT_BRANCH=main
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
_BUILD_WEBSITE_URL=https://appwrite.io
_BUILD_WEBSITE_VERSION=1.6.x
_BUILD_WEBSITE_VERSION=cloud
_BUILD_GIT_URL=https://github.com/appwrite/website.git
_BUILD_GIT_BRANCH=main
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ You can build the docker image and run it with docker compose:
```bash
docker compose build \
--build-arg _BUILD_WEBSITE_URL=https://appwrite.io \
--build-arg _BUILD_WEBSITE_VERSION=1.6.x \
--build-arg _BUILD_WEBSITE_VERSION=cloud \
--build-arg _BUILD_GIT_URL=https://github.com/appwrite/website.git \
--build-arg _BUILD_GIT_BRANCH=main

docker compose up
docker compose up -d
```

### 6. Linting and Formatting
Expand Down
34 changes: 17 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
FROM node:18-alpine AS base
FROM node:18-slim AS base

RUN apk add --no-cache \
python3 \
make \
g++ \
build-base \
git
RUN apt-get update && apt-get install -y python3 make g++ git

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
Expand All @@ -14,14 +9,12 @@ RUN corepack prepare pnpm@10.0.0 --activate

FROM base AS builder

COPY package.json pnpm-lock.yaml /usr/src/app/
WORKDIR /usr/src/app

RUN pnpm fetch --prod
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod

COPY . /usr/src/app

RUN pnpm install
COPY . .

ARG _BUILD_GIT_URL
ARG _BUILD_GIT_BRANCH
Expand All @@ -35,14 +28,21 @@ ENV _BUILD_WEBSITE_VERSION=${_BUILD_WEBSITE_VERSION}

RUN pnpm run fetch-sources

FROM base
FROM node:18-slim AS prod

ENV NODE_ENV=production
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable
RUN corepack prepare pnpm@10.0.0 --activate

WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/node_modules /usr/src/app/node_modules
COPY --from=builder /usr/src/app/sources /usr/src/app/sources
COPY --from=builder /usr/src/app/package.json /usr/src/app/
COPY --from=builder /usr/src/app/src /usr/src/app/src
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/sources ./sources
COPY --from=builder /usr/src/app/package.json ./
COPY --from=builder /usr/src/app/src ./src

ENV _APP_ASSISTANT_OPENAI_API_KEY=''

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"dev": "nodemon src/main.js",
"lint": "eslint src",
"format": "prettier --write \"src/**/*.js\" \"scripts/**/*.js\"",
"fetch-sources": "node scripts/git-sources.js && node scripts/web-sources.js"
"fetch-sources": "node scripts/git-sources.js && node scripts/web-sources.js",
"make-sources": "node scripts/web-sources.js"
},
"keywords": [],
"author": "",
Expand Down
1 change: 1 addition & 0 deletions scripts/git-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ await execa("git", ["config", "core.sparseCheckout", "true"], {
});

await execa("git", ["checkout", GIT_BRANCH], { cwd: LOCAL_PATH });
await execa("rm", ["-rf", `${LOCAL_PATH}/.git`]);
1 change: 1 addition & 0 deletions scripts/test-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const PROMPTS = [
"How do I use the users API to create a new user with Dart?",
"What endpoints are available for the Avatars API? I'm using the PHP SDK",
"How to use Appwrite with React?",
"How do I host a simple static website with Appwrite?"
];
const TESTS_FOLDER = "./tests";

Expand Down
67 changes: 40 additions & 27 deletions scripts/web-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ const SDKS = [
"server-graphql",
"server-rest",
];

const SERVICES = [
"account",
"avatars",
"databases",
"functions",
"locale",
"messaging",
"sites",
"storage",
"teams",
"users",
Expand All @@ -55,37 +57,48 @@ const SERVICES = [
await execa("rm", ["-rf", LOCAL_PATH]);
await mkdir(LOCAL_PATH, { recursive: true });

console.log("Downloading reference pages...");
await Promise.all(
SDKS.map((sdk) => {
return mkdir(`${LOCAL_PATH}/${sdk}/`, { recursive: true });
}),
);

for (const sdk of SDKS) {
await mkdir(`./sources/references/${sdk}/`, { recursive: true });
console.log("Downloading reference pages...");

for (const service of SERVICES) {
const url = new URL(
`/docs/references/${WEBSITE_VERSION}/${sdk}/${service}`,
WEBSITE_URL,
);
const start = Date.now();

const response = await fetch(url.toString());
await Promise.all(
SDKS.flatMap((sdk) =>
SERVICES.map(async (service) => {
const url = new URL(
`/docs/references/${WEBSITE_VERSION}/${sdk}/${service}`,
WEBSITE_URL,
);

const html = await response.text();
if (!html) {
console.warn(`Skipping page ${url} - no content found`);
continue;
}
try {
const response = await fetch(url.toString());
const html = await response.text();
if (!html) {
console.warn(`Skipping page ${url} - no content found`);
return;
}

// Ignore the header and footer
const matches = html.match(
/<main class="contents" id="main">(.*?)<\/main>/s,
);
if (!matches || !matches[0]) {
console.warn(`Skipping page ${url} - no <main> tag found`);
continue;
}
const matches = html.match(
/<main class="contents" id="main">(.*?)<\/main>/s,
);
if (!matches || !matches[0]) {
console.warn(`Skipping page ${url} - no <main> tag found`);
return;
}

const markdown = NodeHtmlMarkdown.translate(matches[0]);
const markdown = NodeHtmlMarkdown.translate(matches[0]);
await writeFile(`${LOCAL_PATH}/${sdk}/${service}.md`, markdown);
console.log(`Created ./sources/references/${sdk}/${service}.md`);
} catch (e) {
console.warn(`Failed to download ${url}:`, e);
}
}),
),
);

await writeFile(`./sources/references/${sdk}/${service}.md`, markdown);
console.log(`Created ./sources/references/${sdk}/${service}.md`);
}
}
console.log("References created in", (Date.now() - start) / 1000, "seconds");
9 changes: 6 additions & 3 deletions src/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const getDocumentation = async () => {
*/
const getReferences = async () => {
const filenames = await glob(["./sources/references/**/*.md"]);
const version = process.env._BUILD_WEBSITE_VERSION ?? "cloud";

return Promise.all(
filenames.map(async (filename) => {
Expand All @@ -52,7 +53,7 @@ const getReferences = async () => {
const { sdk, service } = parseReferenceData(filename);
const metadata = {
filename,
url: `https://appwrite.io/docs/references/cloud/${sdk}/${service}`,
url: `https://appwrite.io/docs/references/${version}/${sdk}/${service}`,
};

return new Document({
Expand All @@ -64,8 +65,10 @@ const getReferences = async () => {
};

export const getDocuments = async () => {
const documentation = await getDocumentation();
const references = await getReferences();
const [documentation, references] = await Promise.all([
getDocumentation(),
getReferences(),
]);

return await splitDocuments([...documentation, ...references]);
};
Expand Down
2 changes: 1 addition & 1 deletion src/embeddings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getDocuments } from "./documents.js";
/**
* @returns {Promise<VectorStoreRetriever<HNSWLib>>}
*/
export const intializeDocumentRetriever = async () => {
export const initializeDocumentRetriever = async () => {
Comment thread
ChiragAgg5k marked this conversation as resolved.
const embeddings = new OpenAIEmbeddings({
openAIApiKey: process.env._APP_ASSISTANT_OPENAI_API_KEY,
});
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express from "express";
import {
getRagChain,
getOpenAIChat,
intializeDocumentRetriever as initializeRetriever,
initializeDocumentRetriever as initializeRetriever,
} from "./embeddings.js";

const app = express();
Expand Down
34 changes: 34 additions & 0 deletions tests/how-do-i-host-a-simple-static-website-with-appwrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
To host a simple static website with Appwrite, you can follow these steps:

1. **Create an Account and Project**: If you haven't already, create an account on Appwrite and set up your first project.

2. **Add a Platform**: In your project, add a platform by selecting **Web app**. Set the **Hostname** to `localhost` or the domain where you plan to host your web app.

3. **Configure Your Site**:
- Navigate to your site in the Appwrite Console.
- Go to the **Settings** tab and then the **Build settings** section.
- Select the **Static site** checkbox.
- Ensure the correct install command, build command, and output directory are set.
- Provide a fallback file for advanced routing and proper page handling.

4. **Deploy Your Site**:
- You can deploy your site manually by uploading your source code through the Appwrite Console.
- Alternatively, set up automatic deployments from a Git repository for continuous integration and delivery.

5. **Redeploy**: After configuring your settings, click on the **Update** button and redeploy your site.

6. **Install Appwrite SDK (Optional)**: If you need to interact with Appwrite services, you can install the Appwrite Web SDK using a package manager:
```sh
npm install appwrite@18.1.1
```
Or include it via CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/appwrite@17.0.0"></script>
```

By following these steps, you can host and manage your static website directly within the Appwrite platform.

Sources:
- https://appwrite.io/docs/products/sites/rendering/static/
- https://appwrite.io/docs/products/sites/deploy-manually/
- https://appwrite.io/docs/quick-starts/web/
Loading