Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:22-alpine

# Create app directory
WORKDIR /usr/src/app

# Copy package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install

# Copy the application code
COPY . .

# Expose the app's port
EXPOSE 3000

# Start the application
CMD ["yarn", "tsx", "server.ts"]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
> - Tested (~100% Code coverage)
> - ✅ Ready for new ČSFD 2025!
> - You can use in:
> - Docker – [_How to do it?_](#-docker)
> - Firebase function
> - AWS λ (lambda function)
> - CloudFlare Worker
Expand Down Expand Up @@ -361,6 +362,43 @@ csfd

_Note: You can not use both parameters `includesOnly` and `excludes`. Parameter `includesOnly` has a priority._

## 📦 Docker

You can use this library in Docker.

We have [prepared a Docker image](https://hub.docker.com/r/bartholomej/node-csfd-api) for you.

### Prebuilt image

```bash
docker pull bartholomej/node-csfd-api
```

### Build & run your own image

> Build image

```bash
docker build -t node-csfd-api .
```

> Run image on port 3000

```bash
docker run -p 3000:3000 node-csfd-api
```

> Open http://localhost:3000

### API endpoints

> Some examples

- `/movies/535121`
- `/search/quentin+tarantino`
- `/creators/2120`
- `/user-ratings/912-bart`

## 🧑‍💻 Used by

### Web extensions
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@babel/preset-typescript": "^7.26.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.15.0",
"@types/express": "^5.0.0",
"@types/node": "^22.9.3",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
Expand All @@ -44,6 +45,7 @@
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"express": "^4.21.1",
"globals": "^15.12.0",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
Expand Down Expand Up @@ -82,4 +84,4 @@
"lint-staged": {
"*.ts": "eslint --cache --fix"
}
}
}
66 changes: 66 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import express from 'express';
import packageJson from './package.json';
import { csfd } from './src';
import { CSFDFilmTypes } from './src/interfaces/global';

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

app.get('/', (_, res) => {
res.json({
name: packageJson.name,
version: packageJson.version,
docs: packageJson.homepage,
links: ['/movie/:id', '/creator/:id', '/search/:query', '/user-ratings/:id']
});
});

app.get(['/movie/', '/creator/', '/search/', '/user-ratings/'], (req, res) => {
res.json({ error: `ID is missing. Provide ID like this: ${req.url}${req.url.endsWith('/') ? '' : '/'}1234` });
});

app.get('/movie/:id', async (req, res) => {
try {
const movie = await csfd.movie(+req.params.id);
res.json(movie);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch movie data' });
}
});

app.get('/creator/:id', async (req, res) => {
try {
const result = await csfd.creator(+req.params.id);
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch creator data: ' + error });
}
});

app.get('/search/:query', async (req, res) => {
try {
const result = await csfd.search(req.params.query);
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch search data: ' + error });
}
});

app.get('/user-ratings/:id', async (req, res) => {
const { allPages, allPagesDelay, excludes, includesOnly } = req.query;
try {
const result = await csfd.userRatings(req.params.id, {
allPages: allPages === 'true',
allPagesDelay: allPagesDelay ? +allPagesDelay : undefined,
excludes: excludes ? (excludes as string).split(',') as CSFDFilmTypes[] : undefined,
includesOnly: includesOnly ? (includesOnly as string).split(',') as CSFDFilmTypes[] : undefined
});
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch user-ratings data: ' + error });
}
});

app.listen(port, () => {
console.log(`API is running on http://localhost:${port}`);
});
Loading