Skip to content

Commit

Permalink
add docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
arieschwartzman committed Dec 28, 2023
1 parent e92b55d commit 0f33482
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
.env
5 changes: 1 addition & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
"name": "Launch Program",
"program": "./dist/app.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"sourceMaps": true,
"env": {
"API_KEY": ""
}
"sourceMaps": true
}
]
}
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use an official Node.js LTS runtime as the base image
FROM node:lts

# Set the working directory in the Docker image to /app
WORKDIR /app

# Copy package.json and package-lock.json to the Docker image
COPY package*.json ./

# Install the application dependencies in the Docker image
RUN npm install

# Copy the rest of the application to the Docker image
COPY . .

# Compile TypeScript to JavaScript
RUN npm run build

# Expose port 3000 for the application
EXPOSE 3000

# Define the command to run the application
CMD [ "node", "dist/app.js" ]
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ This project requires the following environment variables:
- `PORT` - The port on which the server will run. If not provided, defaults to 3000.
- `API_KEY` - The API key for authenticating requests.

## Configuring .env for Local Development

To configure your application for local development, you need to create a `.env` file in the root directory of your project. This file will contain key-value pairs, which represent environment variables.

Here's an example of what your `.env` file might look like:

PORT=3000

API_KEY=your_api_key


## Running the Application

To start the server, run:
Expand All @@ -37,6 +48,25 @@ npm start

- `POST /sign` - Creates a JWT from the provided payload.

For example:

```bash
curl -X POST https://{host}/sign \
-H 'Content-Type: application/json' \
-H 'x-api-key: your_api_key' \
-d '{
"secret": "your_secret",
"audience": "your_audience"
}'
```
If the request is successful, you will receive a response like this:

```json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWRpZW5jZSI6InlvdXJfYXVkaWVuY2UiLCJpYXQiOjE1MTYyMzkwMjIsImV4cCI6MTUxNjI0MjYyMn0.ih1a0wR5p07s7B8eIiKA7TbCqxGVuCwK3I2C6l1BwEI"
}
```

## Built With

- [Express](https://expressjs.com/) - The web framework used
Expand Down
39 changes: 38 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.5"
"@types/jsonwebtoken": "^9.0.5",
"typescript": "^4.5.4"
}
}
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import dotenv from 'dotenv';
import express, { Request, Response } from 'express';
import jwt from 'jsonwebtoken';

const app = express();
dotenv.config();

const PORT = process.env.PORT || 3000;
const API_KEY = process.env.API_KEY;

Expand All @@ -11,6 +14,9 @@ if (!API_KEY) {
process.exit(1);
}

console.log(`API_KEY: ${API_KEY}`);


// Middleware for JSON payload parsing
app.use(express.json());

Expand Down

0 comments on commit 0f33482

Please sign in to comment.