Vertx web Routing - ruby

I'm new to vertx-web. I'm building web application using ruby vertx-web. I would like to serve static file (index.html) . and My index.html packed inside webroot folder.
My index.html file will load for http://localhost:8088. I need to serve index.html for localhost:8088/demo OR localhost:8088/test OR http://localhost:8088/* (* could be anything and it should serve index.html).
directory structure:
frontend
webroot
index.html
index.css
sever.rb
Any help will be appreciated.

Try this:
router.route("/static/*").handler(&VertxWeb::StaticHandler.create().setWebRoot("webroot").method(:handle))

You could define a default route as last route and set a handler which only sends the index.html file:
router.route().handler(rc -> {
rc.response().sendFile("webroot/index.html");
});
This is the Java version but translating it to Ruby should be easy.

following code works for me.
router.route_with_regex(".*/index.html").handler() { |routingContext| router.route().handler(&VertxWeb::StaticHandler.create().method(:handle))
response = routingContext.response()
response.put_header("content-type", "text/html")
response.set_chunked(true)
response.send_file("webroot/index.html")
}

Related

Laravel App Not Loading CSS From Public Installation Not In public_html

I've installed a pre-made Laravel app and followed the documentation to extract it to the public root except in the documentation they are installing it into public_html, but I have it in a subdomain in a folder named "test" which is on the same level as public_html.
All the CSS and JS should be loading from the public subdirectory, but they try to look for it in the main root folder.
For example, this file returns a 404 error:
https://test.mydomain.com/css/style.css
The file is actually at this location:
https://test.mydomain.com/public/css/style.css
The absolute path of the file is:
/home/mydomain/test/public/css/style.css
Instead of:
/home/mydomain/public_html/public/css/style.css
What environment or config file isn't set correctly and how do I set it to use the correct directory?
UPDATE
Changing the ASSET_URL to "public" fixed the first issue, but now the same thing is happening with the admin.
The app tries to load the dashboard with this URL:
https://test.mydomain.com/admin/dashboard
The page loads all the assets normally when I remove the word "admin" from the URL:
https://test.mydomain.com/dashboard
But this doesn't work for all the pages.
You can try to put public directory path in below given conflagration file.
Config File Path : config/app.php (asset_url)
'asset_url' => env('ASSET_URL', 'https://test.mydomain.com/public/')

Unable to boot ApiServiceProvider, configure an API domain or prefix in Laravel

I am using Laravel-8 as restful api. Also I am using Dingo Package. Initially the url was:
http://localhost:8888/myapp/server/public
And it was loading correctly.
However, I decided to remove public from the url. So I followed these steps:
Rename server.php in your Laravel root folder to index.php
Copy the .htaccess file from /public directory to your Laravel root folder.
When I tried to reload the url as:
http://localhost:8888/myapp/server
I got this error:
Unable to boot ApiServiceProvider, configure an API domain or prefix
C:\xampp\htdocs\myapp\server\vendor\dingo\api\src\Provider\DingoServiceProvider.php
protected function registerConfig()
{
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/api.php'), 'api');
if (! $this->app->runningInConsole() && empty($this->config('prefix')) && empty($this->config('domain'))) {
throw new RuntimeException('Unable to boot ApiServiceProvider, configure an API domain or prefix.');
}
}
Even with:
http://localhost:8888/mygeapp/server/public/
The same error still applies
How do I resolve this?
Thanks
Please be sure to configure your IPI PREFIX in the env file
API_PREFIX=api

Laravel + Nginx: can we serve app from /something and from a different folder?

On disk
/var/www/mainapp -> some other legacy .php files without any magic url handling
/var/www/laravel - > my laravel app
I must serve
accessing domain.tld -> mainapp
accessing domain.tld/laravel -> my laravel app
The problem is also that Laravel's app are entirelyt served from /var/www/laravel/public/index.php as you of course know
I am not able to set nginx to serve /laravel and all subroutes using laravel app
Something as simple as this should work:
server {
server_name domain.tld;
location / {
root /var/www/mainapp;
# add php/fpm config
}
location /laravel {
root /var/www/laravel;
# add php/fpm config
}
}

Uploading images to Public_html file rather than public project file

Had this working but just updated my website on the server and it seems to have made all my uploaded files head to my public folder in my project rather than the public_html. Any idea on which file i must have uploaded and the fix?
You said you had it working before.
Was that on the same server...live?
If so, then could that be a server issue and not necessarily laravel issue?
Maybe you should ask your host for help and clarifications about what changed?
If you are convinced it was about what you changed...then care to show us?
Ideally if the server is cpanel, you will want to upload all your laravel files into your home's directly...then all your /public folder content into public_html
It will look like this:
.cpanel/
app/
etc/
bootstrap/
mail/
public_html/
content from your laravel /public directory
vendor/
...etc
You also need to go into your /public_html and edit the index.php content:
require __DIR__.’/../vendor/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And make sure it points to the correct location of your bootstrap folder..if you follow the structure above, then its ok.
Lastly, confirm that your PHP is indeed >= PHP7.0
With help from this answer: https://stackoverflow.com/a/50261573/3475551
I managed to get laravel to save uploaded files to my servers public directory instead of app/public.
Edit app/Providers/AppServiceProvider.php like this:
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../../public_html');
});
}
Hope this helps.

How to set routing between laravel and custom module?

I have two modules one is a Laravel Extension and Second one is custom module(just some html,css,js file).
I have created Two folders as its project requirement.
Let say Folder1(basic bootstrap home page) and Folder2(complete laravel Application).
Website Root
Folder1
--index.html
--css
--js
Folder2
--app
--config
--database
--other laravel foldes
How can configure routes so that from index.php I can call some
controller of laravel with is in Folder2.
And From some view of laravel redirect to index.php in Folder1
I know its not perfect way to do that but its requiremnt of client and we cann't change that.
Thanks in Advance.
You can try to use Puli and add your module Folder1 as a resource.
They have a twig extension too so using it in a Laravel should be pretty seamless
Do following steps make sure you have backup.
1.Put all content folder public folde to root folder so that laravel can understand this is your root.
2.Edit index.php and provide file path to them
require __DIR__.'folder2/bootstrap/autoload.php';
$app = require_once __DIR__.'folder2/bootstrap/app.php';
3.Now laravel routing is working here. so all your laravel routs are now filne.
4.Now for all html files in folder1 you can make a .htaccess rules or make a general rule in root folder.
Redirect 301 /home /folder1/home.html.
5.Now when you access site.com/home it will redirected to folder1 and when you access site.com/laravelHome it will go to folder2.
Hope this will help you.

Resources