Skip to content

Commit

Permalink
fix: One more attempt to fix static files (#260)
Browse files Browse the repository at this point in the history
* fix: Add static files to the dist folder

* fix: small fix with path to copy

* fix: Skip API guarding for .js files

* Move to path.join for static files

* Move to relative path

* Add explicit file for static
  • Loading branch information
Andrew Nikitin authored Jun 13, 2023
1 parent 0f07360 commit abaed7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { UserInfo } from './controllers/user_info.js'
import path from 'path'

const swagger_options = {
customJs: './custom_button.js',
customJs: '/static/custom_button.js',
}

dotenv.config()
Expand Down Expand Up @@ -56,7 +56,6 @@ class App {
this.express.use(handleAuthRoutes(configLogToExpress))
this.express.use(withLogto(configLogToExpress))
this.express.use(express.text())
this.express.use(express.static(path.join(process.cwd(), '/src/static')))

this.express.use(
'/swagger',
Expand Down Expand Up @@ -96,6 +95,12 @@ class App {
app.post(`/account`, new CustomerController().create)
app.get(`/account`, new CustomerController().get)

// static files
app.get('/static/custom_button.js',
express.static(
path.join(process.cwd(), '/dist/src'),
{extensions: ['js'], index: false}))

// 404 for all other requests
app.all('*', (req, res) => res.status(400).send('Bad request'))
}
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class Authentication {
response.locals.customerId = DEFAULT_CUSTOMER_ID
} else {
return response.status(400).json({
error: `Unauthorized error. It requires ENABLE_AUTH=true and bearerToken in headers or CUSTOMER_ID to be set.`
error: `Unauthorized error. It requires ENABLE_AUTHENTICATION=true and bearerToken in headers or DEFAULT_CUSTOMER_ID to be set.`
})
}
next()
Expand Down
2 changes: 1 addition & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MethodToScope {

export class ApiGuarding {
private routeToScoupe: MethodToScope[] = []
private static pathSkip = ['/', '/swagger', '/user']
private static pathSkip = ['/', '/swagger', '/user', '/static/custom_button.js']
private static regExpSkip = new RegExp("^/.*js")
constructor() {
this.registerRoute('/account', 'GET', 'account:read')
Expand Down

0 comments on commit abaed7a

Please sign in to comment.