Skip to content
Open
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
73 changes: 37 additions & 36 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"jest/globals": true
'env': {
'browser': true,
'es6': true,
'node': true,
'jest/globals': true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
'extends': [
'eslint:recommended',
'plugin:react/recommended'
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
'parserOptions': {
'ecmaFeatures': {
'jsx': true
},
"ecmaVersion": 2018,
"sourceType": "module"
'ecmaVersion': 2018,
'sourceType': 'module'
},
"plugins": [
"react", "jest"
'plugins': [
'react', 'jest'
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
'rules': {
'indent': [
'error',
2
],
"quotes": [
"error",
"single"
'linebreak-style': [
'error',
'unix'
],
"semi": [
"error",
"never"
'quotes': [
'error',
'single'
],
"eqeqeq": "error",
"no-trailing-spaces": "error",
"object-curly-spacing": [
"error", "always"
'semi': [
'error',
'never'
],
"arrow-spacing": [
"error", { "before": true, "after": true }
'eqeqeq': 'error',
'no-trailing-spaces': 'error',
'object-curly-spacing': [
'error', 'always'
],
"no-console": "error",
"react/prop-types": 0
'arrow-spacing': [
'error', { 'before': true, 'after': true }
],
'no-console': 'error',
'react/prop-types': 0
}
}
16 changes: 16 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=22.21.1
FROM node:${NODE_VERSION}-slim AS base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY package-lock.json package.json ./
RUN npm ci --include=dev

# Copy application code
COPY . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --omit=dev


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start th server by default, this can be overwritten at runtime
EXPOSE 5050
CMD [ "npm", "run", "start" ]
17 changes: 11 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const express = require("express");
const app = express();
const express = require('express')
const app = express()

// get the port from env variable
const PORT = process.env.PORT || 5000;
const PORT = process.env.PORT || 5050

app.use(express.static("dist"));
app.use(express.static('dist'))

app.get('/version', (req, res) => {
res.send('1')
})

app.listen(PORT, () => {
console.log(`server started on port ${PORT}`);
});
// eslint-disable-next-line no-console
console.log(`server started on port ${PORT}`)
})
29 changes: 29 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# fly.toml app configuration file generated for full-stack-open-pokedex-m0t3wa on 2026-01-24T03:08:29Z
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'full-stack-open-pokedex-m0t3wa'
primary_region = 'yyz'

[build]

[env]
PORT = "5050"

[processes]
app = "node app.js"

[http_service]
internal_port = 5050
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
memory_mb = 256
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { BrowserRouter as Router, Routes, Route, useMatch } from 'react-router-dom'
import { Routes, Route, useMatch } from 'react-router-dom'
import { useApi } from './useApi'
import LoadingSpinner from './LoadingSpinner'
import ErrorMessage from './ErrorMessage'
Expand Down
3 changes: 1 addition & 2 deletions src/PokemonPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const PokemonPage = ({ previous, next }) => {
const normalAbility = pokemon.abilities.find((ability) => !ability.is_hidden)
const hiddenAbility = pokemon.abilities.find((ability) => ability.is_hidden === true)

console.log('hiddenAbility=', hiddenAbility)
return (
<>
<div className="links">
{previous && <Link to={`/pokemon/${previous.name}`}>Previous</Link>}
<Link to="/">Home</Link>
{next && <Link to={`/pokemon/${previous.name}`}>Next</Link>}
{next && <Link to={`/pokemon/${next.name}`}>Next</Link>}
</div>
<div className={`pokemon-page pokemon-type-${type.name}`}>
<div className="pokemon-image" style={{ backgroundImage: `url(${pokemon.sprites.front_default})` }} />
Expand Down
6 changes: 3 additions & 3 deletions test/App.jest.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react'
import axiosMock from 'axios'
import { act } from 'react-dom/test-utils'
import '@testing-library/jest-dom'
import { BrowserRouter as Router } from 'react-router-dom'
import { MemoryRouter } from 'react-router-dom'
import App from '../src/App'

jest.mock('axios')
Expand All @@ -18,7 +18,7 @@ describe('<App />', () => {
}
)
await act(async () => {
render(<Router><App/></Router>)
render(<MemoryRouter><App/></MemoryRouter>)
})
expect(axiosMock.get).toHaveBeenCalledTimes(1)
expect(axiosMock.get).toHaveBeenCalledWith('https://pokeapi.co/api/v2/pokemon/?limit=50')
Expand All @@ -27,7 +27,7 @@ describe('<App />', () => {
it('shows error', async () => {
axiosMock.get.mockRejectedValueOnce(new Error())
await act(async () => {
render(<Router><App/></Router>)
render(<MemoryRouter><App/></MemoryRouter>)
})
expect(screen.getByTestId('error')).toBeVisible()
})
Expand Down
2 changes: 1 addition & 1 deletion test/PokemonPage.jest.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ describe('<PokemonPage />', () => {

expect(screen.queryByText('Previous')).toBeNull()
expect(screen.queryByText('Next')).toBeNull()
})
})
})