Deploy on Heroku found error: GET 502 Bad Gateway favicon.ico - heroku

I have followed this tutorial and some alike but it showed me the error as title.
https://dev.to/hawacodes/deploying-a-mern-app-with-heroku-3km7
I have also put env on heroku
config var
Here are my practice project github
https://github.com/NDK2020/sheyshop
And my current Heroku app
https://practice-sheyshop.herokuapp.com/
I have tried all the way, but it wasn't work. I can see the website load as in the dev environment and then the screen blank within seconds, open the network tab in Firefox it stated:
error Image
Log from heroku
Log image

I think I have found the answer, in my server.ts, I have to put this code block after this the route declaration. From this
if (process.env.NODE_ENV === "production") {
console.log("PRODUCTION MODE ACTIVE");
//app.use('/', express.static("/client/build"));
app.use(express.static("./client/build"));
app.get('*', (req: any, res: any) => {
res.sendFile(path.resolve(__dirname, './client/build','index.html'));
})
}
app.use('/api/products/', productRoute)
app.use('/api/users/', userRoute)
app.use('/api/orders/', ordersRoute);
To this
app.use('/api/products/', productRoute)
app.use('/api/users/', userRoute)
app.use('/api/orders/', ordersRoute);
if (process.env.NODE_ENV === "production") {
console.log("PRODUCTION MODE ACTIVE");
//app.use('/', express.static("/client/build"));
app.use(express.static("./client/build"));
app.get('*', (req: any, res: any) => {
res.sendFile(path.resolve(__dirname, './client/build','index.html'));
})
}

Related

Static font files not served in Vite dev environnement

I am trying to switch from webpack to vite in an existing Laravel application. For local development I use Laravel Valet.
If I run vite build everything works correctly (images, fonts, scss), but if I run vite the only bug I get is that it doesn't get the fonts path correctly (Error 404):
https://example.test:5173/fonts/open-sans/regular-400.woff2
Without the port it would work.
I've read a lot and I think I've tried everything:
Attempts (failed) in the Vite configuration:
export default defineConfig(({ command, mode }) => {
return {
// root: './',
// base: './',
// publicDir: 'public',
// assetsInclude: ['public/fonts'],
// Rest of the configuration are Plugins (Laravel, Vue), Alias etc...
}
});
So I try to change the root, base, publicDir nor assetsInclude and don't remember what else... and nothing of them hasn't solved my problem.
The structure of my public folder:
- public
- build
- assets
- fonts
- images
css font-face:
#font-face {
...
url('/fonts/open-sans/regular-400.woff2') format('woff2'),
url('/fonts/open-sans/regular-400.woff') format('woff');
}
The solution I found was to add the alias for the font path (public/font) only in the dev environment:
export default defineConfig(({ command, mode }) => {
const alias = {
(some alias),
};
// dev environment
if (command === 'serve') {
Object.assign(alias, { '/fonts': path.resolve(__dirname, 'public/fonts') });
}
return {
...
resolve: {
alias
}
}
});
I think it's a Vite bug and I don't know if that's the best solution for that, so I'm open to any suggestions.

Authentication problem with running ionic app using firebase on native device, everything works fine with live reload

Good morning!
I have a strange problem where i can run & authenticate my user on my ios device perfectly fine running the app using the command below.
ionic capacitor run -l --external
Using an emulator, it works sometimes, though not always.
When I try to deploy the app using Xcode, the app opens and looks normal, but if I try to send authentication requests to firebase, the app just keeps on loading, although the requests are successfully performed.
I first thought the problem was because of using LocalStorage so I rebuilt everything using Ionic Storage. But that didn't help.
I tried different versions of adding the Firebase SDK in Swift or in the Cocoa Pods file but the behaviour doesn't change so I don't believe that this is a issue with a wrong firebase configuration, what is the proper way to do this by the way - or is Ionic doing this for me already?
The output of Xcode doesn't provide any valuable information either.
2021-12-01 11:20:13.990875+0100 App[3162:27661] Writing analzed variants.
2021-12-01 11:20:14.125754+0100 App[3162:27661] KeyboardPlugin: resize mode - native
⚡️ Loading app at capacitor://localhost...
2021-12-01 11:20:14.552490+0100 App[3162:27661] Writing analzed variants.
⚡️ WebView loaded
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ [log] - null
⚡️ To Native -> App addListener 60635511
2021-12-01 11:20:21.393141+0100 App[3162:27661] [Accessibility] WKContentView[#] set up: # pid: # MACH_PORT -830404096
login-function
loginWithEmail() {
let email: string = this.loginForm.get("email").value;
let password: string = this.loginForm.get("password").value;
this.loadingService.present({
message: "Logging in . . ."
});
this.authService
.loginWithEmail(email, password)
.then((result) => {
this.authService.SetUserData(result.user)
this.resetLoginForm();
this.loginSuccess();
this.router.navigateByUrl("/tabs/intensity");
})
.catch(error => {
console.log(error);
this.loginFailed(error);
});
}
login-success
loginSuccess() {
this.loadingService.dismiss();
this.toastService.present({
message: "Welcome back!",
duration: 3000,
color: "secondary"
});
}
login-with-email
import { AngularFireAuth } from "#angular/fire/compat/auth";
...
async loginWithEmail(email: string, password: string) {
return await this.afAuth.signInWithEmailAndPassword(email, password);
}
set user-data function
SetUserData(user) {
this.user = user;
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
const userData: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified
}
return userRef.set(userData, {
merge: true
})
}
Running it multiple times some times I get this error.
API error: <_UIKBCompatInputView: 0x7fb965726040; frame = (0 0; 0 0); layer = <CALayer: 0x600002f718a0>> returned 0 width, assuming UIViewNoIntrinsicMetric
I am really stuck on this and would appreciate any help. Thank you & kind regards.
Ionic 6.18.1
Angular 12.1.5
Xcode Version 13.1 (13A1030d)

404 not found on /.well-known/assetlinks.json

I am getting 404 error when accessing /.well-known/assetlinks.json on my site.
It works locally but not when I deploy it to Heroku. I am using Svelte on Sapper with polka server.
I tried adding it to the static folder, where all the other static resources work fine. Also tried with a dynamic route with no luck.
My guess is it might have to do with the leading dot or something wrong in my service-worker...
Any ideas on how to solve it or how to debug it?
Found the solution here: https://github.com/lukeed/sirv/tree/master/packages/sirv#optsextensions
opts.dotfiles Type: Boolean Default: false
Allow requests to dotfiles (files or directories beginning with a .).
even if it says
Note: Requests to /.well-known/* are always allowed.
I had to specify the option as true.
Sample code:
polka({ server })
.use(
force_ssl,
compression({ threshold: 0 }),
sirv('static', { dev: dev, dotfiles: true }),
sapper.middleware()
)
.listen(PORT, err => {
if (err) console.log('error', err);
});

VuePress: How can I use https in dev server?

Is there any hook to enable https in VuePress dev server?
1. Current solution.
I directly add one line to node_modules/#vuepress/core/lib/node/dev/index.js. This works well, but nasty.
createServer () {
const contentBase = path.resolve(this.context.sourceDir, '.vuepress/public')
const serverConfig = Object.assign({
https: true, // <--- Added this line.
disableHostCheck: true,
compress: true,
clientLogLevel: 'error',
vuejs/vuepress - /packages/#vuepress/core/lib/node/dev/index.js#L197-L237
2. Background
Because Chrome has changed it's security policy, CORS.
3. What I've tried.
I've tried but not working.
webpack - devServer.https
docs/.vuepress/config.js
configureWebpack: (config, isServer) => {
if (!config.devServer) {
config.devServer = {}
}
Object.assign(config.devServer, {
https: true,
})
}
No proper hook
VuePress - Plugin Option API - beforeDevServer
VuePress - Plugin Option API - afterDevServer
No command option for https.
vuejs/vuepress - /packages/vuepress/lib/registerCoreCommands.js#L18-L31
module.exports = function (cli, options) {
cli
.command(`dev [targetDir]`, 'start development server')
.option('-p, --port <port>', 'use specified port (default: 8080)')
.option('-t, --temp <temp>', 'set the directory of the temporary file')
.option('-c, --cache [cache]', 'set the directory of cache')
.option('--host <host>', 'use specified host (default: 0.0.0.0)')
.option('--no-cache', 'clean the cache before build')
.option('--no-clear-screen', 'do not clear screen when dev server is ready')
.option('--debug', 'start development server in debug mode')
.option('--silent', 'start development server in silent mode')
.option('--open', 'open browser when ready')
.action((sourceDir = '.', commandOptions) => {
const { debug, silent } = commandOptions
4. Related links.
vuejs/vuepress - Support devServer.proxy in configureWebpack #858
vuejs/vuepress - Sunsetting webpack-serve #1195
Add the following settings to config.js.
//
// docs/.vuepress/config.js
//
module.exports = {
devServer: {
https: true
},
}
How to run Vue.js dev serve with https? - Stackoverflow
Thank you for your guidance in many ways.

Directory path is incorrect when running from cypress test runner

When I login from normal browser the login is successful with the URL : http://neelesh.zapto.org:8084/EnrolMe/indHome.html
But when I run the script from Cypress the directory location is not appended and the new URL after login is formed as : http://neelesh.zapto.org:8084/__/indHome.html
I have tried setting cypress.json with
{
"chromeWebSecurity": false,
"modifyObstructiveCode" : false
}
I have tried on chrome/electron(head and headless).
Below is my code snippet:
describe('My First Test Suite', function() {
it('My First test case', function() {
cy.visit("http://neelesh.zapto.org:8084/EnrolMe")
cy.get("#login").click()
cy.get("input[value='Individual']").click()
cy.get("#username").type('1234567890')
cy.get("#pwd").type('0646')
Cypress.Cookies.debug(true)
cy.clearCookies()
cy.get("#login").click()
cy.wait(6000)
})
})
When I run the script from Cypress the directory location is not appended and the new URL after login is formed as : http://neelesh.zapto.org:8084/__/indHome.html
It should be redirected as : http://neelesh.zapto.org:8084/EnrolMe/indHome.html
Can anyone help me on this?
This sounds like an issue with "Frame Busting". There's a related discussion for Cypress GitHub Issue #992 which may lend some help.
Your application code may contain problematic frame busting code like the following:
if (window.top !== window.self) {
window.top.location.href = window.self.location.href;
}
You can get around this by changing your application code's reference to window.self from the Application Window to the Cypress Test Runner window (window.top).
Cypress emits a series of events as it runs in your browser. You can use the emitted window:before:load application event to ensure it's done before you attempt to login.
// cypress/support/index.js
Cypress.on('window:before:load', (win) => {
Object.defineProperty(win, 'self', {
get: () => {
return window.top
}
})
})

Resources