Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: One more attempt to fix static files #260

Merged
merged 9 commits into from
Jun 13, 2023
Merged
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