Skip to content

Commit

Permalink
fix: serve public folder
Browse files Browse the repository at this point in the history
  • Loading branch information
denchiklut committed Oct 13, 2024
1 parent 92d2d03 commit ff5bee3
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ You can use .env file to specify environment variables. This file is ignored by
3. If this variable needs to be accessible from both `client` & `server` make sure it's name starts with prefix `CLIENT_`
4. You can access environment variable via `getENV` function.
This function will return a proper value based on environment (client/server) and cast it to a proper type based on `envSchema` from `step 2` (string/number/boolean)
5. Important note! Unlike with Next.js apps, environment variables in this setup are `not baked` into the `bundle` at build time. This allows you to `build` the app `once` (e.g., for staging) and `reuse` the same build in other environments, such as production, without needing to rebuild for each environment.

#### Global variables

Expand Down
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default {
'^@shared/(.*)': '<rootDir>/src/client/components/@shared/$1',
'^pages/(.*)$': '<rootDir>/src/client/pages/$1',
'^utils/(.*)$': '<rootDir>/src/client/utils/$1',
'^assets/(.*)$': '<rootDir>/src/client/assets/$1',
'/config/react-forget$': '<rootDir>/config/react-forget',
'\\.(icon|image).(svg)$': '<rootDir>/config/spec/svgr.ts',
'\\.(css|scss)$': 'identity-obj-proxy'
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
12 changes: 9 additions & 3 deletions assets/offline/index.html → public/offline/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<link href="../icons/favicon.ico" rel="icon" />
Expand Down Expand Up @@ -70,11 +70,17 @@
transition: 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
color: white;
background-color: black;
box-shadow: #00000033 0 3px 1px -2px, #00000024 0 2px 2px 0, #0000001f 0 1px 5px 0;
box-shadow:
#00000033 0 3px 1px -2px,
#00000024 0 2px 2px 0,
#0000001f 0 1px 5px 0;
}

.button:hover {
box-shadow: #00000033 0 2px 4px -1px, #00000024 0 4px 5px 0, #0000001f 0 1px 10px 0;
box-shadow:
#00000033 0 2px 4px -1px,
#00000024 0 4px 5px 0,
#0000001f 0 1px 10px 0;
}

@media only screen and (max-width: 480px) {
Expand Down
2 changes: 1 addition & 1 deletion assets/spa/index.html → public/spa/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<title>SSR App</title>
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/favicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { resolve } from 'path'
import serveFavicon from 'serve-favicon'

export const favicon = () => {
const favPath = IS_DEV ? resolve('assets/icons') : resolve(__dirname, '../client/icons')
const favPath = IS_DEV ? resolve('public/icons') : resolve(__dirname, '../client/icons')
return serveFavicon(resolve(favPath, 'favicon.ico'))
}
2 changes: 1 addition & 1 deletion src/server/router/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { resolve } from 'path'
import { Router, static as staticRoute } from 'express'

export function staticRoutes(router: Router) {
router.use(staticRoute(IS_DEV ? 'assets' : resolve(__dirname, '../client')))
router.use(staticRoute(IS_DEV ? 'public' : resolve(__dirname, '../client')))
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@shared/*": ["src/client/components/@shared/*"],
"pages/*": ["src/client/pages/*"],
"utils/*": ["src/client/utils/*"],
"assets/*": ["src/client/assets/*"],
"config/*": ["config/*"]
},
"typeRoots": ["@types", "node_modules/@types"]
Expand Down
21 changes: 16 additions & 5 deletions webpack/plugins/copy.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ import { join } from 'path'
import CopyPlugin from 'copy-webpack-plugin'
import { IS_PROD, ROOT_DIR } from '../utils'

const config = {
patterns: [{ from: join(ROOT_DIR, 'assets/icons'), to: 'icons' }]
}

export const copyPlugin = IS_PROD && new CopyPlugin(config)
export const copyPlugin =
IS_PROD &&
new CopyPlugin({
patterns: [
{
from: join(ROOT_DIR, 'public'),
filter(path) {
const ignore = [
join(ROOT_DIR, 'public/offline/index.html'),
join(ROOT_DIR, 'public/spa/index.html')
]
return !ignore.some(v => path.startsWith(v))
}
}
]
})
8 changes: 5 additions & 3 deletions webpack/plugins/html.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { join } from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import { ROOT_DIR, IS_PROD } from '../utils'
import { ROOT_DIR, IS_PROD, PUBLIC_PATH } from '../utils'

const offlineConfig = {
filename: 'pwa/offline.html',
inject: true,
template: join(ROOT_DIR, 'assets/offline/index.html')
template: join(ROOT_DIR, 'public/offline/index.html'),
publicPath: PUBLIC_PATH
}

const spaConfig = {
filename: 'index.html',
inject: true,
template: join(ROOT_DIR, 'assets/spa/index.html')
template: join(ROOT_DIR, 'public/spa/index.html'),
publicPath: PUBLIC_PATH
}

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion webpack/utils/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const devServerConfig = {
port,
host: hostname,
historyApiFallback: true,
static: { directory: join(ROOT_DIR, 'assets') }
static: { directory: join(ROOT_DIR, 'public') }
}

0 comments on commit ff5bee3

Please sign in to comment.