Skip to content

Commit

Permalink
chore: Add specific build for public page
Browse files Browse the repository at this point in the history
When user access `/preview` or `/preview/`, the stack will return assets from . This modification avoid unauthorized status code on access to vendors and extra files
  • Loading branch information
cballevre committed Feb 2, 2023
1 parent 16b1e14 commit 61898bb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ configurationFiles.push(
configurationFiles.push(
require('cozy-scripts/config/webpack.config.css-modules')
)
configurationFiles.push(require('./config/public.config.js'))

const extraConfig = {
resolve: {
modules: ['node_modules', SRC_DIR],
Expand Down
26 changes: 26 additions & 0 deletions config/public.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const CopyPlugin = require('copy-webpack-plugin')

module.exports = {
plugins: [
new CopyPlugin([
{
from: `src/targets/vendor/assets/icon.svg`,
to: 'public/icon.svg'
},
{
from: `src/targets/vendor/assets/favicon*`,
to: 'public/',
flatten: true
},
{
from: `src/targets/vendor/assets/apple-touch-icon.png`,
to: 'public/apple-touch-icon.png'
},
{
from: `src/targets/vendor/assets/safari-pinned-tab.svg`,
to: 'public/safari-pinned-tab.svg'
},
{ from: `src/targets/vendor/assets`, ignore: ['.gitkeep'] }
])
]
}
4 changes: 2 additions & 2 deletions manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"public": false
},
"/public": {
"folder": "/",
"folder": "/public",
"index": "index.html",
"public": true
},
"/preview": {
"folder": "/",
"folder": "/public",
"index": "index.html",
"public": true
}
Expand Down
37 changes: 37 additions & 0 deletions src/targets/public/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="{{.Locale}}">
<head>
<meta charset="utf-8" />
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link
rel="icon"
type="image/png"
href="./favicon-32x32.png"
sizes="32x32"
/>
<link
rel="icon"
type="image/png"
href="./favicon-16x16.png"
sizes="16x16"
/>
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#297EF2" />
<meta name="theme-color" content="#ffffff" />
<meta
name="viewport"
content="width=device-width, height=device-height, initial-scale=1, viewport-fit=cover"
/>
<% _.forEach(htmlWebpackPlugin.files.css, function(file) { %>
<link rel="stylesheet" href="<%- file %>" />
<% }); %>
<% _.forEach(htmlWebpackPlugin.files.js, function(file) { %>
<script src="<%- file %>" defer></script>
<% }); %>
<% if (__STACK_ASSETS__) { %>
{{.CozyBar}}
<% } %>
</head>
<div role="application" data-cozy="{{.CozyData}}"></div>
</html>
1 change: 1 addition & 0 deletions src/targets/public/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../browser/index'

0 comments on commit 61898bb

Please sign in to comment.