Browse Source
Merge pull request #280 from butlerx/assets-static
allow assets to be served project root rather then pwd
pull/284/head
v2.0.2
Cian Butler
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
19 additions and
7 deletions
-
package.json
-
src/server/socketServer/assets.ts
-
src/server/socketServer/middleware.ts
-
src/server/socketServer/shared/path.ts
-
yarn.lock
|
|
@ -1,6 +1,6 @@ |
|
|
|
{ |
|
|
|
"name": "wetty", |
|
|
|
"version": "2.0.1", |
|
|
|
"version": "2.0.2", |
|
|
|
"description": "WeTTY = Web + TTY. Terminal access in browser over http/https", |
|
|
|
"homepage": "https://github.com/butlerx/wetty", |
|
|
|
"license": "MIT", |
|
|
@ -104,6 +104,7 @@ |
|
|
|
"express": "^4.17.1", |
|
|
|
"express-winston": "^4.0.5", |
|
|
|
"file-type": "^12.3.0", |
|
|
|
"find-up": "^5.0.0", |
|
|
|
"fresh": "^0.5.2", |
|
|
|
"fs-extra": "^9.0.1", |
|
|
|
"helmet": "^4.1.0", |
|
|
|
|
|
@ -1,6 +1,5 @@ |
|
|
|
import { resolve } from 'path'; |
|
|
|
import express from 'express'; |
|
|
|
import { assetsPath } from './shared/path.js'; |
|
|
|
|
|
|
|
export const trim = (str: string): string => str.replace(/\/*$/, ''); |
|
|
|
export const serveStatic = (path: string) => |
|
|
|
express.static(resolve(process.cwd(), 'build', path)); |
|
|
|
export const serveStatic = (path: string) => express.static(assetsPath(path)); |
|
|
|
|
|
@ -3,7 +3,7 @@ import etag from 'etag'; |
|
|
|
import fresh from 'fresh'; |
|
|
|
import parseUrl from 'parseurl'; |
|
|
|
import fs from 'fs'; |
|
|
|
import { join, resolve } from 'path'; |
|
|
|
import { assetsPath } from './shared/path.js'; |
|
|
|
|
|
|
|
const ONE_YEAR_MS = 60 * 60 * 24 * 365 * 1000; // 1 year
|
|
|
|
|
|
|
@ -43,7 +43,7 @@ export function redirect( |
|
|
|
* @returns middleware |
|
|
|
*/ |
|
|
|
export function favicon(basePath: string): RequestHandler { |
|
|
|
const path = resolve(join('build', 'assets', 'favicon.ico')); |
|
|
|
const path = assetsPath('assets', 'favicon.ico'); |
|
|
|
return (req: Request, res: Response, next: NextFunction): void => { |
|
|
|
if (getPathName(req) !== `${basePath}/favicon.ico`) { |
|
|
|
next(); |
|
|
|
|
|
@ -0,0 +1,12 @@ |
|
|
|
import findUp from 'find-up'; |
|
|
|
import { resolve, dirname } from 'path'; |
|
|
|
import { fileURLToPath } from 'url'; |
|
|
|
|
|
|
|
const filePath = dirname( |
|
|
|
findUp.sync('package.json', { |
|
|
|
cwd: dirname(fileURLToPath(import.meta.url)), |
|
|
|
}) || process.cwd(), |
|
|
|
); |
|
|
|
|
|
|
|
export const assetsPath = (...args: string[]) => |
|
|
|
resolve(filePath, 'build', ...args); |
|
|
@ -2323,7 +2323,7 @@ find-cache-dir@^3.3.1: |
|
|
|
make-dir "^3.0.2" |
|
|
|
pkg-dir "^4.1.0" |
|
|
|
|
|
|
|
find-up@5.0.0: |
|
|
|
find-up@5.0.0, find-up@^5.0.0: |
|
|
|
version "5.0.0" |
|
|
|
resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" |
|
|
|
integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== |
|
|
|