add /api routes and health check in docker-compose

This commit is contained in:
lamacchinadesiderante 2024-04-28 12:13:24 +02:00
parent eb9c6a22a7
commit f2efe33dba
5 changed files with 58 additions and 2 deletions

View File

@ -8,6 +8,13 @@ services:
restart: always
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:3000/api/status || exit 1
interval: 60s
retries: 5
start_period: 20s
timeout: 10s
build: .
ports:

View File

@ -1,11 +1,25 @@
const createNextIntlPlugin = require('next-intl/plugin');
const withNextIntl = createNextIntlPlugin();
const path = require('path')
module.exports = withNextIntl({
sassOptions: {
includePaths: [path.join(__dirname, 'src/styles')],
},
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{ key: "Access-Control-Allow-Methods", value: "GET,DELETE,PATCH,POST,PUT" },
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" },
]
}
]
}
})

View File

@ -0,0 +1,7 @@
import { getAppVersion } from '@/utils/info/version'
import { NextResponse } from 'next/server'
export async function GET() {
const version = await getAppVersion()
return NextResponse.json({ version })
}

View File

@ -0,0 +1,5 @@
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
return NextResponse.json({ msg: 'OK' })
}

23
src/utils/info/version.ts Normal file
View File

@ -0,0 +1,23 @@
import fs from 'fs/promises';
import path from 'path';
export const getAppVersion = async (): Promise<string> => {
let version = ''
try {
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
const data = await fs.readFile(packageJsonPath, 'utf8');
const packageJson = JSON.parse(data);
version = packageJson.version
} catch (error) {
// handle error
}
return version
}