Skip to content

Commit

Permalink
rest(hosting): config for hosting (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfroeller committed Jan 23, 2024
1 parent 5a9330f commit f5c4f48
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 2 deletions.
60 changes: 60 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost # http://localhost/propromo/public # http://propromo.test
APP_SERVICE_URL=https://propromo-rest-de8dfcad6586.herokuapp.com

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=propromo
DB_USERNAME=propromo
DB_PASSWORD=propromo

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
17 changes: 17 additions & 0 deletions rest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM oven/bun

WORKDIR /app

COPY package.json .
COPY bun.lockb .

RUN bun install --production

COPY src src
COPY tsconfig.json .
# COPY public public

ENV NODE_ENV production
CMD ["bun", "src/index.ts"]

EXPOSE 80
16 changes: 15 additions & 1 deletion rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@ To start the development server run:
bun run dev
```

Open http://localhost:3000/ with your browser to see the result.
Open http://localhost:3000/ with your browser to see the result.

## Production

### Deployment

```bash
# build and push the image in . to heroku
heroku container:push web
```

```bash
# deploy the container to heroku using the pushed image
heroku container:release web
```
1 change: 1 addition & 0 deletions rest/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker image build -t propromo/rest .
Binary file modified rest/bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions rest/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# for development
version: '3.9'

services:
app:
image: "oven/bun"
# override default entrypoint allows us to do `bun install` before serving
entrypoint: []
# execute bun install before we start the dev server in watch mode
command: "/bin/sh -c 'bun install && bun run --watch src/index.ts'"
# expose the right ports
ports: ["3000:3000"]
# setup a host mounted volume to sync changes to the container
volumes: ["./:/home/bun/app"]
1 change: 1 addition & 0 deletions rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "bun run --watch src/index.ts"
},
"dependencies": {
"@elysiajs/cors": "^0.8.0",
"dotenv": "^16.3.2",
"elysia": "latest",
"octokit": "^3.1.2"
Expand Down
6 changes: 5 additions & 1 deletion rest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Elysia } from "elysia"; // https://elysiajs.com/introduction.html
import { cors } from '@elysiajs/cors'; // https://elysiajs.com/plugins/cors.html#cors-plugin
import { Octokit } from "octokit"; // unused: App // https://github.com/octokit/octokit.js | https://github.com/octokit/types.ts
import 'dotenv/config'; // process.env.<ENV_VAR_NAME>

const GITHUB_PAT = process.env.GITHUB_PAT;
const octokit = new Octokit({ auth: GITHUB_PAT });

const app = new Elysia()
.use(cors({
origin: 'https://propromo.duckdns.org'
}))
.get("/", () => "Hello Elysia")
.get('/organization/:organization_name', async ({ params: { organization_name } }) => {
const {
Expand Down Expand Up @@ -45,7 +49,7 @@ const app = new Elysia()

return JSON.stringify(organization, null, 2);
})
.listen(3000);
.listen(process.env.PORT || 3000);

console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
Expand Down

0 comments on commit f5c4f48

Please sign in to comment.