Skip to content

Commit

Permalink
Add static support
Browse files Browse the repository at this point in the history
  • Loading branch information
thezzisu committed Jan 31, 2021
1 parent 45674c3 commit ac592b2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ dist
# Runtime data
/data/**/*
!/data/.gitkeep
/static/**/*
!/static/.gitkeep
1 change: 1 addition & 0 deletions src/misc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'

export const PROJECT_ROOT = path.resolve(__dirname, '..', '..')
export const DATA_DIR = path.join(PROJECT_ROOT, 'data')
export const STATIC_DIR = path.join(PROJECT_ROOT, 'static')
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const APP_PACKAGE_JSON = require(path.join(PROJECT_ROOT, 'package.json'))
export const APP_VERSION: string = APP_PACKAGE_JSON.version
7 changes: 6 additions & 1 deletion src/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fastify from 'fastify'
import fastifySensible from 'fastify-sensible'
import fastifyStatic from 'fastify-static'
import { Server } from 'socket.io'
import { EntityManager, getManager } from 'typeorm'
import { APP_VERSION } from '../misc/constants'
import { APP_VERSION, STATIC_DIR } from '../misc/constants'
import { ENV_IS_DEVELOPMENT } from '../misc/env'
import io from './io'
import api from './api'
Expand Down Expand Up @@ -37,6 +38,10 @@ export async function startWebService(): Promise<void> {
})
}

await server.register(fastifyStatic, {
root: STATIC_DIR
})

// Inject manager
const manager = getManager()
server.decorate('manager', manager)
Expand Down
Empty file added static/.gitkeep
Empty file.

0 comments on commit ac592b2

Please sign in to comment.