Svelte routing on production not work with dynamic build links (Svelte Router SPA) - svelte-3

fetching a json-file with a "url"-string. With this I'm building an url in svelte. For the routing I'm using Svelte Router SPA. In Dev-Mode everything is working fine but after deploying the pages are not found. This happens only on "dynamic-build-links" through the json-feed. If I write it manually it works.
thanks for helping.
routes.js
{
name: 'prod/:product',
component: PublicProduct,
}
package.json
"start": "sirv public -s"
Svelte Router SPA

Related

Using Digitalocean Spaces as CDN for Next.js _next directory

I have a Kubernetes cluster on Digitalocean where www.example.com points to my Next.js application. This works as expected, however it serves all the assets from that same pod where my Next.js is running:
https://www.example.com/_next/static/chunks/webpack-16e102404d6e7c36f3ae.js
https://www.example.com/_next/static/chunks/framework-852c1b21255b4351ab3d.js
and so on.
Now I would like to serve these static files from a CDN instead, so I started researching on how to do this. One thing I found is that DigitalOcean offers CDN functionality through their Spaces, and one other thing is the documentation from Next.js here: https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix
So I set up a DigitalOcean Space, which is now available through https://cdn.example.com and also I followed the instructed from Next.js and modified my next.js.config file like this:
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
// Use the CDN in production and localhost for development.
assetPrefix: isProd ? 'https://cdn.example.com' : '',
future: {
webpack5: true,
},
};
And deployed it. But of course, this doesn't work - the files that are generated during the build stage never get uploaded to my CDN. So now when I open my site it doesn't load any of the static files, because these URLs don't exist:
https://cdn.example.com/_next/static/chunks/webpack-16e102404d6e7c36f3ae.js
https://cdn.example.com/_next/static/chunks/framework-852c1b21255b4351ab3d.js
So now my question is, how do I set this up? As I understood there are two possible ways to do this.
1: is to configure my DigitalOcean Space to point at the _next folder of my pod, the first request will then serve the file still from my pod, but every request after that will then serve the file from the CDN
2: during the build phase in deployment I would have to upload my files to the CDN's _next folder.
And here is where I am stuck - I have no idea how to do either. For option 1, I tried finding such a setting inside DigitalOcean but couldn't find anything.
For option 2, this is my current workflow:
I make changes to the code
I commit the changes to Github
Github Actions is configured so that it will automatically build a new Docker image
Github Actions then pushes this new Docker image to my registry
Github Actions then updates my Kubernetes cluster, tells it to use this new image for my Next.js application
If I would have to make changes to this workflow to upload things to the CDN, where would I have to do it? My Dockerfile is a multistage file (3 stages) and only in the 2nd stage I run the build command.

Rails Back-end and Vue Front-end on a same port

I have this rails application which handles the backend for the app and I also have a Vue project in the root of the same directory acting as a front end. Now, the rails server runs on port:3000 and Vue runs on Port:8081 by default.
I need to make sure both communicate through a single port.
If you are using webpack or the Vue CLI you can easily define a reverse proxy in the configuration of your front-end project. Here is an example of such a webpack config:
devServer: {
proxy: {
'/api': 'http://localhost:3000'
}
}
When defining such a configuration, your front-end devserver will redirect each request from http://localhost:8081/api/* to http://localhost:3000/api/*. You can also define another pattern than /api depending on your needs.
In Vue CLI, you can use the same configuration and add it to the vue.config.js file. Make sure to add the webpackConfig into the section configureWebpack:
module.exports = {
configureWebpack: {
[...the config like above...]
}
};
Here are some documentation references:
Webpack Dev Server: Proxy
Vue CLI Webpack Config
The above described configuration works for the development environment. The productive environment must be handled differently, because there is no webpack devserver in production. You need to build the static HTML/JS/CSS content with webpack and then either put the generated code into the Rails application and serve it from there statically or you use two web servers (one for Rails and one for serving the static files) and put a reverse proxy in front of them.

Vue subdomain in development & production

I'm have following (abstract) project structure:
src/brands
src/admin
src/home
Brands & admin are a pure vue project, home is a nuxt project. I'm trying to get the brands & admin project to run on their own subdomain (brands.website.com & admin.website.com, respectively), and home on the main domain. The deploy to production/staging happens via docker (with an nginx image), and I was thinking to just copy a nginx config file from my project to the docker image to point the files in the dist folder to the correct html file (not sure how yet, I need to research that first).
For development, I used vue.config.js (since I'm using v3 of the vue cli) and I have setup the following:
index: {
entry: 'src/index/main.js',
filename: 'index.html',
},
brands: {
entry: 'src/brands/main.js',
filename: 'brands/index.html',
},
admin: {
entry: 'src/admin/main.js',
filename: 'admin/index.html',
},
I can reach the brands module via localhost:8080/brands, admin module via localhost:8080/admin and the homepage via localhost:8080, but the problem is that on my index page I'm gonna have a route that is /brands, so that would probably overwrite the brands module route with the page from nuxt (or vice versa). Now is my question if there is a better way of doing this (for example to enable subdomains in vue / localhost) and if not, is the way I'm wanting to copy the nginx config to my docker image a good practice? Or not?
Thanks in advance!
I have a similar project architecture. I have a single repo with multiple vue/nuxt projects. Each of my projects is its own npm/webpack project and is accessed by subdomain when developing locally.
Based on your example, this is how I would setup the projects.
Modify your hosts file:
127.0.0.1 website.localhost brands.website.localhost admin.website.localhost
Using localhost as the TLD was my personal decision, feel free to name the domains anyway you like.
Configure webpack dev server to serve each project at the corresponding subdomain + port.
src/brands: https://brands.website.localhost:8080
src/admin: https://admin.website.localhost:8081
src/home: https://website.localhost:8082
Whats nice about this configuration is that your dev URLs match your production URLs. https://brands.website.localhost:8080 -> https://brands.website.com
Each project will have complete control over the domain's subpaths and won't clobber other project's routes, which you alluded to with the /brands route.

Internal Server Error with Craft CMS 3

I'm installing Craft CMS 3 on a staging environment at http://staging.overlookpro.com and am having issues getting the CMS to show. I've installed Craft CMS 3 using Composer and selecting staging.overlookpro.com as my web root folder on my server. The folders that are installed are in this format: staging.overlookpro.com/craft/*.
On my local copy I am using MAMP on macOS and the CMS works completely fine. But for some reason the staging and production sites keep showing an Internal Server Error. I've made sure I had PHP 7 installed, but the control panel will not show.
if it shows completely fine in your local environment, so make sure your URL should point to the web directory.
For admin login : http://<Hostname>/index.php?p=admin/install
You have to use it in this format, then it will work out:
https://wedot.ch/index.php?p=admin/install
Or you can use it like this:
https://wedot.ch/admin/install
Your URL must Point to your web Directory.
Use this URL: http://<Hostname>/index.php?p=admin/install

Remove ember-cli-mirage from ember

I am using ember-cli-mirage to serve for requests. As I have my rails api to serve those request, how i shd remove or uninstall ember-cli-mirage from my ember ?
If am removing mirage folder, am getting build error !!
You should leave Mirage installed (and the folder on disk) but disable the server whenever you want to use your actual backend API. This will let you use Mirage in selective environments, for example in testing.
By default, Mirage is disabled in production, and also in development when using the -proxy option.
To disable Mirage explicitly, you can set the enabled config option to false. For example, to always disable in development:
// config/environment.js
...
if (environment === 'development') {
ENV['ember-cli-mirage'] = {
enabled: false
};
}
Leave mirage installed, if you want to use your backend api just launch ember with
ember s --proxy http://localhost:8000
if api's are running on your machine on port 8000.
More info on mirage official site: http://www.ember-cli-mirage.com/docs/v0.3.x/configuration/#enabled

Resources