Skip to content

Commit

Permalink
feat: support public directory
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jun 13, 2020
1 parent 5503330 commit 1e97a44
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/frourio/__test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const client = api(aspida(undefined, { baseURL }))
let server: Server

beforeEach(async () => {
server = (await run({ port, staticDir: 'packages/frourio/public' })).server
server = (await run({ port })).server
})

afterEach(fn => server.close(fn))
Expand Down
7 changes: 2 additions & 5 deletions packages/frourio/server/$app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'reflect-metadata'
import { tmpdir } from 'os'
import { Server } from 'http'
import path from 'path'
import express, { Express } from 'express'
import multer from 'multer'
import helmet from 'helmet'
Expand Down Expand Up @@ -96,11 +97,7 @@ export const run = async (config: Config) => {
app.use(router)
}

if (config.staticDir) {
;(Array.isArray(config.staticDir) ? config.staticDir : [config.staticDir]).forEach(dir =>
app.use(express.static(dir))
)
}
app.use(express.static(path.join(__dirname, 'public')))

let connection: Connection

Expand Down
1 change: 0 additions & 1 deletion packages/frourio/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import { run } from './$app'
run({
port: 10000,
basePath: '/api',
staticDir: 'packages/frourio/public',
cors: true
})
File renamed without changes.
7 changes: 2 additions & 5 deletions packages/frourio/src/buildServerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default (input: string): Template => {
import 'reflect-metadata'
import { tmpdir } from 'os'
import { Server } from 'http'
import path from 'path'
import express, { Express } from 'express'
import multer from 'multer'
import helmet from 'helmet'
Expand Down Expand Up @@ -46,11 +47,7 @@ export const run = async (config: Config) => {
app.use(router)
}
if (config.staticDir) {
;(Array.isArray(config.staticDir) ? config.staticDir : [config.staticDir]).forEach(dir =>
app.use(express.static(dir))
)
}
app.use(express.static(path.join(__dirname, 'public')))
let connection: Connection
Expand Down
1 change: 0 additions & 1 deletion packages/frourio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export * as Validator from 'class-validator'
export type Config = {
port: number | string
basePath?: string
staticDir?: string | string[]
helmet?: boolean | IHelmetConfiguration
cors?: boolean | CorsOptions
typeorm?: ConnectionOptions
Expand Down

0 comments on commit 1e97a44

Please sign in to comment.