How to setup up the folder structure of angular 2 app? - php

I have been following the Angular 2 Tour of Heroes tutorial and Quick Start guide on anuglar.io. In the tutorials all the of the files are directly under the app folder. I have started my own project and I want to set up the folder structure where I Have a components folder, services folder, and directives folder all under the app folder for the project. Under each of these folders I would also like to have folders the house each individual component to include the ts, js, map, and the html files relating to the component so for instance. It would look something like this:
-My_Project
- app
- components
-app
- app.component.ts
- app.component.js
- app.component.map
- app.component.html
-logon
- logon.component.ts
- logon.component.js
- logon.component.map
- logon.component.html
- services
-user
- user.services.ts
- user.services.js
- user.services.map
so on and so forth.
I understand about using absolute and relative paths and using ../ to move up to the parent folder and ../../ to go back two folders in the path, but for some reason it doesn't seem to be working with the lite server. This works just fine when i run the app with Windows IIS 7.5. When I try to run the compiler I get errors of the following nature:
app - Copy/app.component.ts(6,32): error TS2307: Cannot find module './logon/logon.component'.
I am using the following to reference the logon.component file from the app.component file.
import { LogonComponent } from '../logon/logon.component';
Also I have some PHP files in a php folder located in the Project folder. This again works fine when ran on Windows IIS 7.5 but when i try and run it with the lite server I get a 404 error when these php files are needed.
Edit
Here is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
Here is my pacakage.json
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},

Related

start laravel project inside electron project

i created a laravel project inside electron js the issue is that first I have to use php artisan serve commad inside the laravel project then only when I start my electron with npm start the laravel project will work how can i over come this issue
what i want is when i start the electron project with npm start the php artisan serve must also work with it
here is a diretory list of my app
I followed the documentation your provided here : Laravel desktop application using Electron Js
and everything seems to work pretty well, however you need to know:
You don't need to use php artisan serve npm will do all the work for you.
Everything must be in one directory,
start by creating a new directory for example: stack
inside the stack follow step 1,2 from the documentation you provided.
make sure to install php-server :
npm i --save node-php-server
in the step 3 ("Making directories") inside stack create two directories as follow:
stack/php : here copy your php folder that contains the bin/php.exe ....etc
stack/www : here create your laravel project (Note: make it here, not a sub directory, so it's like stack/www/public , stack/www/artisan ....etc).
if you want to edit the directories as you want, pay attention to the following lines in step 4 from the link above:
as a note:
phpServer.createServer({
port: port,
hostname: host,
base: `${__dirname}/www/public`,
keepalive: false,
open: false,
bin: `${__dirname}/php/php.exe`,
router: __dirname + '/www/server.php'
});
base: is the laravel public folder
bin : is the bin file to PHP CLI
router: is the server.php file from laravel project

Issue with Storage on shared hosting

I am deploying my first project on a shared hosting.
I followed this tutorial to deploy the website and turn the public folder into the public_html folder of my hosting plan.
When I upload an image from my website (with storeAs() method), the file is uploaded in the private/storage folder, not the public one (where I would like).
The asset() function try to display the image from public_html/storage.
What can I do ?
Thank you :)
My files are like this :
private/
- app/
- bootstrap/
- config/
- database/
- resources/
- routes/
- storage/
- tests/
- vendor/
public_html/
- css/
- js/
- images/
- js/
- storage/
(Laravel 8, trying to be hosted on Hostinger)
The tutorial : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
Why does this problem happen?
If you implement and need storage matter in your project then you need to link storage folder to the public folder for security reason and to make the URL simple, clean and readable by the users, so when you upload the laravel project to a server, you need to run the following command line to complete the linking process:
php artisan storage:link
and since you host the laravel project to a shared server, so you don’t have access to a terminal to run the above-mentioned command line . so I’ll show you a way to do that manually without using SSH or the terminal.
Steps to fix the problem
1- At localhost server-side (before uploading the project to the server), make sure that you have done filesystem configuration, then run the following command line:
php artisan storage:link
after that you will get a message “The links have been created.” and that is ok for now.
2- Upload the project to the server, the storage link will not work as you expected, so we need to start fixing this.
3- Go to the public folder you will find a folder called “storage”, delete it.
4- Go to routes folder and open “web.php” file, then copy & paste the following code at the top of the file:
Route::get('/linkstorage', function () {
Artisan::call('storage:link') // this will do the command line job
});
Don’t forget to save the changes.
Also, you can do the same process via “api.php” and using requests tools like postman.
5- Now we just need to run this code, so we need to do the GET request by entering the following URL at browser search bar:
“https://www.your-domain.com/public/index.php/linkstorage”
or
“https://www.your-domain.com/public/linkstorage”
this request will run the above code “Artisan::call('storage:link')” which is, in turn, will run the command line
PHP artisan storage: link
now you can go to the public folder and you will see the “storage” folder created again and marked as a shortcut folder and that means the public storage folder now is linked to the storage folder of the project.
6- Now if you upload or create a file to the storage folder, then it will appear in the public/storage folder too, now you can hit the URL of the file at the search bar of the browser and you will get the file successfully :).
Ok guys i found the solution !
Here is how to deploy your Laravel project on one shared hosting using public_html folder : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
This will work but you can have a problem (like me) with the storeAs() method if you deal with file uploads.
To solve this problem, I edited the MyProject/config/filesystem.php by adding this in the available disks :
'public_folder' => [
'driver' => 'local',
'root' => 'PATH',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Replace PATH with the complete path to your public storage (for example /home/you/domains/mydomain.com/public_html/storage/).
Now, open the controller which manage file upload and edit it like this :
request()->image->storeAs('/uploads', 'filename.png', 'public_folder');
This will upload the request()->image in public_html/storage/uploads/filename.png.
I hope it will help you if you had the same problem as me.

PHP backend inside vuejs project folder

I created a vue/cli 3 project and its in my documents/project folder. Im running it on port 3000 with "npm run serve" command. Now, i want to have a backend folder somewhere to serve PHP files. But i want both the frontend and backend to be in the same folder structure.
Currently, my vue is in my documents folder and my php is in my xampp folder. The problem im having with this is managing 2 folders and git for the same application. Also, this causes my ajax calls from my vue projet to use a silly url such a "http://localhost:80/project/file.php". Id like to use relative paths like "backend/clients/getClient.php" that would be somewhere within my vue project.
This is what i would like:
myProject
frontend
my vue stuff like public and src folders
backend
my php files
It doesnt have to be exactly that way but the point is that now i have a single folder and git for a single project.
thank you.
The way I do this is as follows:
1)
I put the php files in a subfolder the public/ folder in the vue/cli project structure.
That way, these files will get copied to the dist folder on building the project.
For example: I have the file /public/api/endpoint.php, this will end up in dist/api/endpoint.php.
For testing locally I now copy the php files to the xampp/htdocs dir whenever I change them. But I guess you could skip this step by setting up a xampp alias directory. (But I haven't tried this myself yet)
2)
The ajax urls still differ between local development mode and production. To solve this I define a webpack plugin in my vue.config.js:
const webpack = require('webpack')
const API_URL = {
production: JSON.stringify('https://www.project.com/api/endpoint.php'),
development: JSON.stringify('http://localhost/project/api/endpoint.php')
}
// check environment mode
const environment =
process.env.NODE_ENV === 'production' ? 'production' : 'development'
module.exports = {
...
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
API_URL: API_URL[environment]
})
]
},
...
}
Then use this in a vue/js file like:
const apiUrl = API_URL // eslint-disable-line
(the eslint directive is only needed If you have linting turned on with eslint, it will throw an error that API_URL is not defined.)

Laravel vue js deploy application on live

I have created a project on laravel using vue js. Where my frontend is totally based on vue js and i am using laravel apis for backend. My project structure is like :
--app
--bootstrap
--config
--database
--fontend //This is my vue js code
-- assets
-- layout
-- mode_modules
-- pages
-- public
-- resources
... and so on.
I have run this command on my frontend folder
npm run build
It created a folder dist in frontend, now what will be the next step ?
My Server Information Ubuntu (Apache)
You should just copy contents of dist folder on your server main folder, or of you have folder structure with folders like public/www/web, then there.
If you want to run "live" on wamp or xamp then copy to folder www.
Of course if you already have working backend
You just copy contents inside the dist folder from your xampp/wampp folder.
and on Ubuntu server place inside directory /var/www/html folder.
or if you want to place inside any folder on the server like /var/www/html/front
then on front folder place contents inside front folder then point domain to that front fodler.

Is there a way to create an Eclipse project excluding the project name in the path?

Not sure how I can explain this better as I am a beginner to Eclipse application.
I have my web directory set up for php pages. For example, /home/www/phpsite. All the source files exist here.
However, whenever I create a project (say 'myProject') and test any files from the existing path, it includes the project folder in the path name:
/home/www/phpsite/myProject/index.php
and this results 'Not Found' error.
How can I run my php pages in /home/www/phpsite/index.php? The project folder name is always included in testing web pages.
I am not trying to use the workspace directory created by Eclipse. I'd like to code and modify pages directly from Eclipse to my web directory.
Thanks
Follow these steps:
Setup www as your workspace
From the menu: File -> Import -> General -> Existing Folder.....
Promote to project:
Choose project type: PHP
Browse for "phpsite" and finish.

Categories