Skip to content

Commit

Permalink
Add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishi Raj Jain committed Apr 27, 2023
1 parent 0d1a6d7 commit 2b3ee88
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist/
node_modules/
.env
.DS_Store
.edgio
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Deploy with the command:
edg deploy --site=my-open-api-project-on-edgio
```


### Deploy to Railway

Install the [`railway` CLI](https://docs.railway.app/develop/cli) and login to your account:
Expand Down Expand Up @@ -166,16 +165,16 @@ ENTRYPOINT [ "node", "src/index.mjs" ]
```js
// src/index.mjs

import express from "express"
import { OpenAI } from "langchain/llms/openai"
import { ConversationChain } from "langchain/chains"
import express from 'express'
import { OpenAI } from 'langchain/llms/openai'
import { ConversationChain } from 'langchain/chains'

const app = express()
const port = process.env.PORT || 8080

const model = new OpenAI({})

app.post("/chat", express.json(), async (req, res) => {
app.post('/chat', express.json(), async (req, res) => {
const chain = new ConversationChain({ llm: model })
const input = req.body.input
const result = await chain.call({ input })
Expand Down
6 changes: 3 additions & 3 deletions edgio.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
connector: "./edgio",
routes: "./edgio/routes.cjs",
};
connector: './edgio',
routes: './edgio/routes.cjs',
}
35 changes: 15 additions & 20 deletions edgio/build.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
const { join } = require("path");
const { existsSync } = require("fs");
const { nodeFileTrace } = require("@vercel/nft");
const { DeploymentBuilder } = require("@edgio/core/deploy");
const { join } = require('path')
const { existsSync } = require('fs')
const { nodeFileTrace } = require('@vercel/nft')
const { DeploymentBuilder } = require('@edgio/core/deploy')

const appDir = process.cwd();
const appDir = process.cwd()

module.exports = async () => {
const builder = new DeploymentBuilder();
builder.clearPreviousBuildOutput();
if (existsSync(join(appDir, ".env"))) {
builder.addJSAsset(join(appDir, ".env"));
const builder = new DeploymentBuilder()
builder.clearPreviousBuildOutput()
const env = ['.env.production', '.env'].map((i) => join(appDir, i)).find(existsSync)
if (env) {
builder.addJSAsset(env)
}
if (existsSync(join(appDir, ".env.production"))) {
builder.addJSAsset(join(appDir, ".env.production"));
}
const { fileList } = await nodeFileTrace([join(appDir, "src", "index.mjs")]);
fileList.forEach((i) => builder.addJSAsset(join(appDir, i)));
builder.writeFileSync(
join(builder.jsDir, "__backends__", "package.json"),
JSON.stringify({ type: "commonjs" })
);
await builder.build();
};
const { fileList } = await nodeFileTrace([join(appDir, 'src', 'index.mjs')])
fileList.forEach((i) => builder.addJSAsset(join(appDir, i)))
builder.writeFileSync(join(builder.jsDir, '__backends__', 'package.json'), JSON.stringify({ type: 'commonjs' }))
await builder.build()
}
6 changes: 3 additions & 3 deletions edgio/prod.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async (port) => {
process.env.PORT = port.toString();
await import("../src/index.mjs");
};
process.env.PORT = port.toString()
await import('../src/index.mjs')
}
10 changes: 5 additions & 5 deletions edgio/routes.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Router } from "@edgio/core/router";
import { Router } from '@edgio/core/router'

const router = new Router();
const router = new Router()

router.fallback(({ renderWithApp }) => {
renderWithApp();
});
renderWithApp()
})

export default router;
export default router
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "Anthony Campolo",
"license": "MIT",
"scripts": {
"edgio:build": "edgio build"
"edgio:build": "edgio build",
"fmt": "prettier --write '**/*' --ignore-unknown"
},
"dependencies": {
"express": "^4.18.2",
Expand All @@ -18,6 +19,12 @@
"@edgio/devtools": "^6.1.4",
"@edgio/prefetch": "^6.1.4",
"@vercel/nft": "^0.22.6",
"dotenv": "^16.0.3"
"dotenv": "^16.0.3",
"prettier": "^2.8.8"
},
"prettier": {
"semi": false,
"singleQuote": true,
"printWidth": 150
}
}
46 changes: 23 additions & 23 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { join } from "path";
import express from "express";
import { existsSync } from "fs";
import * as dotenv from "dotenv";
import { OpenAI } from "langchain/llms/openai";
import { ConversationChain } from "langchain/chains";
import { join } from 'path'
import express from 'express'
import { existsSync } from 'fs'
import * as dotenv from 'dotenv'
import { OpenAI } from 'langchain/llms/openai'
import { ConversationChain } from 'langchain/chains'

const app = express();
const appDir = process.cwd();
const port = process.env.PORT || 3001;
const app = express()
const appDir = process.cwd()
const port = process.env.PORT || 3001

if (existsSync(join(appDir, ".env"))) {
dotenv.config({ path: join(appDir, ".env") });
} else if (existsSync(join(appDir, ".env.production"))) {
dotenv.config({ path: join(appDir, ".env.production") });
const env = ['.env.production', '.env'].map((i) => join(appDir, i)).find(existsSync)

if (env) {
dotenv.config({ path: env })
} else {
dotenv.config();
dotenv.config()
}

const model = new OpenAI({});
const model = new OpenAI({})

app.post("/chat", express.json(), async (req, res) => {
const chain = new ConversationChain({ llm: model });
const input = req.body.input;
const result = await chain.call({ input });
console.log(result.response);
res.send({ body: result.response });
});
app.post('/chat', express.json(), async (req, res) => {
const chain = new ConversationChain({ llm: model })
const input = req.body.input
const result = await chain.call({ input })
console.log(result.response)
res.send({ body: result.response })
})

app.listen(port, () => console.log(`Listening on port ${port}`));
app.listen(port, () => console.log(`Listening on port ${port}`))

0 comments on commit 2b3ee88

Please sign in to comment.