-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tidy server and enhance ci workflow (#3)
* feat: enhance ci workflow * chore: bump version
- Loading branch information
Showing
11 changed files
with
118 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
node_modules | ||
|
||
*.tsbuildinfo | ||
package.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
releases: | ||
"@aoi-js/server": patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,59 @@ | ||
import fastify from 'fastify' | ||
import fastifySensible from '@fastify/sensible' | ||
import fastifySwagger from '@fastify/swagger' | ||
import fastifySwaggerUi from '@fastify/swagger-ui' | ||
import fastifyStatic from '@fastify/static' | ||
import { apiRoutes } from '../routes/index.js' | ||
import { logger } from '../utils/logger.js' | ||
import { schemaRoutes } from './schemas.js' | ||
import { loadEnv } from '../index.js' | ||
import { frontendPath } from '../utils/module.js' | ||
import { hasModule } from '../utils/module.js' | ||
|
||
const server = fastify({ logger }) | ||
|
||
await server.register(fastifySensible) | ||
|
||
await server.register(schemaRoutes, { prefix: '/schemas' }) | ||
|
||
await server.register(fastifySwagger, { | ||
openapi: { | ||
info: { | ||
title: '@aoi-js/server', | ||
description: 'API Server of the AOI Project', | ||
version: 'latest' | ||
}, | ||
components: { | ||
securitySchemes: { | ||
bearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT' | ||
}, | ||
runnerKeyAuth: { | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'X-Runner-Key' | ||
}, | ||
runnerId: { | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'X-Runner-Id' | ||
} | ||
} | ||
}, | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
] | ||
} | ||
}) | ||
await server.register(fastifySwaggerUi, { | ||
routePrefix: '/docs' | ||
}) | ||
|
||
await server.register(apiRoutes, { prefix: '/api' }) | ||
if (hasModule('@fastify/swagger') && hasModule('@fastify/swagger-ui')) { | ||
logger.warn('Swagger is enabled and is not recommended for production use') | ||
const { default: fastifySwagger } = await import('@fastify/swagger') | ||
const { default: fastifySwaggerUi } = await import('@fastify/swagger-ui') | ||
|
||
const staticRoot = loadEnv('STATIC_ROOT', String, frontendPath) | ||
if (staticRoot) { | ||
await server.register(fastifyStatic, { | ||
root: staticRoot | ||
}) | ||
server.setNotFoundHandler((req, rep) => { | ||
if (req.url.startsWith('/api')) { | ||
return rep.notFound() | ||
await server.register(fastifySwagger, { | ||
openapi: { | ||
info: { | ||
title: '@aoi-js/server', | ||
description: 'API Server of the AOI Project', | ||
version: 'latest' | ||
}, | ||
components: { | ||
securitySchemes: { | ||
bearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT' | ||
}, | ||
runnerKeyAuth: { | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'X-Runner-Key' | ||
}, | ||
runnerId: { | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'X-Runner-Id' | ||
} | ||
} | ||
}, | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
] | ||
} | ||
rep.sendFile('index.html') | ||
}) | ||
await server.register(fastifySwaggerUi, { | ||
routePrefix: '/docs' | ||
}) | ||
} | ||
|
||
await server.register(apiRoutes, { prefix: '/api' }) | ||
|
||
export { server } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM node:18-alpine | ||
|
||
RUN corepack enable | ||
WORKDIR /opt | ||
COPY apps/server/package.tgz /opt/package.tgz | ||
RUN tar -xzf package.tgz && rm package.tgz && mv package aoi-server | ||
WORKDIR /opt/aoi-server | ||
RUN npm install --omit=dev --omit=optional | ||
|
||
USER node | ||
|
||
CMD [ "node", "lib/cli/index.js" ] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters