Can I use "router" in roadhog's "proxy" prop? - antd

When I config my .roadhogrc, roadhog's doc said I can set "proxy" prop same as webpack-dev-server#proxy.
I add a "router" prop, then my page can not load, due to the "index.css" timeout.
So, how to use "proxy" in .roadhogrc?
or any way to change the api to test env in localhost?
I can't find "dva" or "roadhog" tag, so sorry to use "antd" tag.
{
"entry": "src/index.js",
"env": {
"development": {
"extraBabelPlugins": [
"dva-hmr",
"transform-runtime",
["import", { "libraryName": "antd", "style": "css" }]
],
"proxy":{
"router":{
"http://api.eshop.corploft.com" : "http://test.corploft.com"
}
}
},
"production": {
"extraBabelPlugins": [
"transform-runtime",
["import", { "libraryName": "antd", "style": "css" }]
],
"outputPath":"build/yijiayi"
}
}
}

Maybe I told a joke...
All the proxy and mock settings are acting on localhost network, so I can only change the requests to local server. If I want to change a request to other servers, all above settings has no help.
SwitchyOmega (in Chrome App Store) or ihosts can help.

Related

Serilog not creating log file on production server

I've created a C# .net5.0 console application and during testing Serilog has been working without incident, logging to Console and File (same folder; path="log.txt"). However, when I run on the application on our server, neither Console nor File logging sinks are working! I assume now that the issue is not the sinks themselves but Serilog not actually working.
I've tried enabling the self log:
Serilog.Debugging.SelfLog.Enable(msg =>
Console.WriteLine(msg)
);
but even running in the debugger in my dev environment, the Console.WriteLine(msg) line is never called!
My appsettings.json is as follows:
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"System": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "log.txt",
"rollingInterval": "Infinite",
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
"shared": false
}
}
],
"Enrich": [ "FromLogContext" ]
},
"Database": {
"Server": "(local)",
"Database": "ActivbaseLive"
},
"Email": {
"SmtpHost": "localhost",
"SmtpPort": 25,
"SmtpSecurityOption": "None",
"SmtpUsername": null,
"SmtpPassword": null,
"SmtpSender": "\"Activbase Learning Platform\" <noreply#activbase.net>"
}
}
I've tried absolute paths (using double backslashes in appsettings.json).
I've tried pre-creating the log file (e.g. log.txt and log200428.txt) and setting permissions to Everyone Full Control but neither of these changes fix the problem and they don't explain why the Console sink doesn't write either.
Here is how Serilog is being configured during start-up which is where I suspect the problem is (even through it works in dev environment):
return Host.CreateDefaultBuilder()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
})
.UseSerilog((hostContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(hostContext.Configuration);
})
.ConfigureAppConfiguration((hostContext, builder) =>
{
builder.AddEnvironmentVariables();
})
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
...
});
}
Any ideas why Serilog isn't working in production?
The Path you provide should be absolute.
Some thing like this:
"path": "E:/wwwroot/QA/BackgroundWorkerService/Logs/logFile_.log"
Even I had the same issue, the above fix worked fine for me...
For my api application running in IIS: I had to assign the following permissions to the log folder for the IIS_IUSRS. I didn't need an absolute path!

Using antd(React) and antd-mobile(React) in the same project

I am using NextJs, and want to know how can I configure webpack to support both antd and antd in the same time.
Currently, not able to configure webpack correctly
In your next.config.js change antStyles = /antd\/.*?\/style\/css.*?/ to antStyles = /antd.*?\/.*?\/style\/css.*?/. This basically changes the regex to match antd and antd-mobile as well.
Then set your .babelrc to
{
"presets": ["next/babel"],
"plugins": [
["import", { "libraryName": "antd", "style": "css" }, "antd"],
["import", { "libraryName": "antd-mobile", "style": "css" }, "antd-mobile"]
]
}

What is the purpose "Using" in serilog configuration in appsettings.json?

I am confused about the purpose Using in this configuration.
Unfortunately the keyword "using" is a very common word, so googling gave no usable result:
a) When configuring with code, I see no analogous builder method in the samples, just the .WriteTo() methods
b) It is interesting, I even commented it out, still everything works (both the console, both the file).
Are not the two Name elements under the WriteTo element (namely Console and File) are the two sinks here? Maybe the Using is a namespace to look for the classes? (then why it works when commented out? and also this should mean that both Console sink and File sink is under the namespace Serilog.Sinks.Console)
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Debug",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "%TEMP%\\Logs\\mylog.txt"
//"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] [Req: {RequestInfo}] {Message}{NewLine}{Exception}"
}
}
]
}

registering custom protocol at installation process in electron app

Hi I am new to electron and was wondering how i can register a custom protocol for the app at the time of installation process of the app.
I am using electron-builder for building the app. Here is the build build code
"build": {
"appId": "com.test.testapp",
"productName": "testapp",
"asar": true,
"protocols": [{
"name": "testapp",
"schemes": [ "testapp" ]
}],
"nsis": {
"oneClick": false,
"perMachine": true,
"allowToChangeInstallationDirectory": true,
"runAfterFinish": false,
"createDesktopShortcut": true
},
"squirrelWindows": {
"msi": true
},
"directories": {
"output": "distribution"
}
I know that by adding the below line registers the custom protocol
app.setAsDefaultProtocolClient("testapp");
but it only does if i run the app at least the first time.
Which i don't want there is no guarantee that the user will launch the app after installation.
So is there a way that i can register the custom protocol in the installation process using electron-builder
I'm still new to Electron and electron-builder but solved this problem for NSIS-target already. First of all I should note that app.setAsDefaultProtocolClient used to handle custom protocols inside the application as far as I do understand. You need to register this custom protocol using electron-builder itself.
Secondly I need to choose between NSIS and squirrelWindows. NSIS is the preferable as long I understand because Squirrel is less supported and has some problems. Again I'm not an expert but I read something about it. So squirrelWindows section is redundant. You don't specify win.target and it is "nsis" by default.
There is a problem with the custom protocol registration for NSIS target. You can read more here: Protocol (scheme) for windows but there is a workaround. You need to create a file named installer.nsh in your build folder with such a content:
!macro customInstall
DetailPrint "Register evehq-ng URI Handler"
DeleteRegKey HKCR "evehq-ng"
WriteRegStr HKCR "evehq-ng" "" "URL:evehq-ng"
WriteRegStr HKCR "evehq-ng" "EveHQ NG SSO authentication Protocol" ""
WriteRegStr HKCR "evehq-ng\DefaultIcon" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
WriteRegStr HKCR "evehq-ng\shell" "" ""
WriteRegStr HKCR "evehq-ng\shell\Open" "" ""
WriteRegStr HKCR "evehq-ng\shell\Open\command" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME} %1"
!macroend
Replace evehq-ng with your protocol string and EveHQ NG SSO authentication Protocol with your protocol description.
After that you have to set nsis.perMachine to true.
I haven't yet solved this problem for Linux but work in this direction. You can see my code in my proof of concepts project here: EveHQ-NG proof of concepts application.
If you will solve this problem for Linux and MacOS write me a message somehow here or on GitHub.
Hope it helps.
Since you are using electron-builder you can do the following:
"build": {
... other top level electron-builder keys ...
"protocols": [
{
"name": "Custom Protocol Name",
"schemes": [
"customProtocol"
]
}
]
}
In case you wanted to handle customProtocol://some-link with your application.
More details:
https://www.electron.build/configuration/configuration
(Search for protocols; as of now, the documentaion is a little mis-formatted. It's supposed to be the same top-level key as the fileAssociations key above it.)
custom protocol is still opening only after opening the electron application. And I also added installer.nsh inside build folder. I don't know what's the problem.
package.json
{
"name": "electron-project",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"pack": "build --dir",
"dist": "build"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^3.0.8",
"electron-builder": "^20.38.5"
},
"dependencies": {
"axios": "^0.18.0"
},
"build": {
"win": {
"target": "nsis"
},
"nsis": {
"oneClick" : false ,
"allowToChangeInstallationDirectory": true,
"include" : "dist/installer.nsh" ,
"perMachine" : true
},
"protocols": [{
"name": "electron-deep-linking",
"schemes": [
"test"
]
}],
"mac": {
"category": "public.app-category.Reference"
}
}
}
main.js
const { app, BrowserWindow } = require('electron')
const path = require('path')
const url = require('url')
let mainWindow
function createWindow() {
mainWindow = new BrowserWindow({ width: 800, height: 600 })
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.setAsDefaultProtocolClient('test')
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
Electron providing a very simple way to registering custom protocol URL in client machine(Windows, Mac)
so this way we can register and remove our own custom protocol in machine
const {app} = require('electron')
app.on('ready', onReady)
function onReady() {
.... // write other code
if(!app.isDefaultProtocolClient('quickstart')) {
app.setAsDefaultProtocolClient("quickstart", 'C:\\Users\\karthi\\electron-quick-start\\electron-quick-start-win32-x64\\electron-quick-start.exe');
}
}
this code will register the custom protocol in machine, then you can open your app using browser like quickstart://params
for removing the custom protocol in machine
app.removeAsDefaultProtocolClient("quickstart", 'C:\\Users\\karthi\\electron-quick-start\\electron-quick-start-win32-x64\\electron-quick-start.exe');
here i used electron quick start app and i used electron-packager npm for building my app
For more information custom protocol electron-protocol

browser.runtime.connect api not working as expected with Firefox for android?

I am developing an extension for Firefox for Android, but since tabs APIs are not supported on Firefox(Android), I am using the following code. It is working fine on Firefox but when porting it to Firefox Android(52 version), background script messages are not being passed to content script listener.
//Content script code
var myPort = browser.runtime.connect({name:"port-from-cs"});
myPort.postMessage({greeting: "hello from content script"});
myPort.onMessage.addListener(function(m) {
console.log("In content script, received message from background script: ");
console.log(m.greeting);
});
// background script
var portFromCS;
function connected(p) {
portFromCS = p;
portFromCS.postMessage({greeting: "hi there content script!"});
portFromCS.onMessage.addListener(function(m) {
console.log("In background script, received message from content script")
console.log(m.greeting);
portFromCS.postMessage({greeting: "hi there content script!"});
});
}
browser.runtime.onConnect.addListener(connected);
//manifest
{
"version": "0.1.5",
"content_scripts": [
{
"js": [
"js/myContentScript.js",
"js/lib/jquery-1.9.1.min.js"
],
"matches": [
"<all_urls>"
],
"run_at": "document_start"
}
],
"description": "xxx",
"manifest_version": 2,
"name": "xx",
"applications": {
"gecko": {
"id": "vpt#mozilla.org"
}
},
"permissions": [
"webRequest",
"notifications",
"http://*/",
"https://*/",
"storage",
"webRequestBlocking"
],
"background": {
"scripts": [
"js/background.js"
]
},
"web_accessible_resources": [
"xxx.js"
]
}
content script is passing the message to background script, but background script messages are caught by portFromCS.onMessage listener. Is my approach correct?

Resources