init
This commit is contained in:
commit
e31c1c4e49
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
.DS_Store
|
||||||
|
|
||||||
|
db/*
|
||||||
|
!db/.gitkeep
|
||||||
|
|
||||||
|
!nginx
|
||||||
|
nginx/*
|
||||||
|
!nginx/nginx.conf
|
||||||
|
|
||||||
|
!php
|
||||||
|
php/*
|
||||||
|
!php/php.ini
|
||||||
|
|
||||||
|
sveltekit/node_modules
|
||||||
|
sveltekit/build/
|
||||||
|
sveltekit/.svelte-kit/
|
||||||
|
sveltekit/package/
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
39
README.md
Normal file
39
README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
## Docker-compose LEMP
|
||||||
|
### Inkluderar
|
||||||
|
- nginx -> localhost:80
|
||||||
|
- php
|
||||||
|
- mariadb -> mariadb
|
||||||
|
- phpmyadmin -> localhost:8080
|
||||||
|
- composer
|
||||||
|
|
||||||
|
### HowTo
|
||||||
|
|
||||||
|
##### SvelteKit
|
||||||
|
/sveltekit
|
||||||
|
##### API med php
|
||||||
|
/www/public/api
|
||||||
|
##### Starta servern (containern) med
|
||||||
|
docker-compose up -d
|
||||||
|
##### Stoppa servern (containern) med
|
||||||
|
docker-compose down
|
||||||
|
##### Serverns url
|
||||||
|
localhost
|
||||||
|
##### phpmyadmin
|
||||||
|
localhost:8080
|
||||||
|
##### Anslut till MariaDB med php
|
||||||
|
|
||||||
|
````php
|
||||||
|
<?php
|
||||||
|
// Definierar konstanter med användarinformation.
|
||||||
|
define ('DB_USER', 'userName'); // Användare i MariaDB
|
||||||
|
define ('DB_PASSWORD', '12345');
|
||||||
|
define ('DB_HOST', 'mariadb');
|
||||||
|
define ('DB_NAME', 'dbName'); // Databasen som anslutning skall ske till
|
||||||
|
|
||||||
|
// Skapar en anslutning till MariaDB och databasen dbName
|
||||||
|
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8';
|
||||||
|
$db = new PDO($dsn, DB_USER, DB_PASSWORD);
|
||||||
|
?> // Ej nödvändigt att avslut "ren" php med ?>
|
||||||
|
````
|
||||||
|
### ToDo
|
||||||
|
Stöd för https, TLS (ssl).
|
208
config/mysql/my.cnf
Normal file
208
config/mysql/my.cnf
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
# Copyright © 2020 Joel Paulsson, Noah Jarvis
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# MariaDB database server configuration file.
|
||||||
|
#
|
||||||
|
# You can copy this file to one of:
|
||||||
|
# - "/etc/mysql/my.cnf" to set global options,
|
||||||
|
# - "~/.my.cnf" to set user-specific options.
|
||||||
|
#
|
||||||
|
# One can use all long options that the program supports.
|
||||||
|
# Run program with --help to get a list of available options and with
|
||||||
|
# --print-defaults to see which it w ould actually understand and use.
|
||||||
|
#
|
||||||
|
# For explanations see
|
||||||
|
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
|
||||||
|
|
||||||
|
# This will be passed to all mysql clients
|
||||||
|
# It has been reported that passwords should be enclosed with ticks/quotes
|
||||||
|
# escpecially if they contain "#" chars...
|
||||||
|
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
|
||||||
|
[client]
|
||||||
|
port = 3306
|
||||||
|
socket = /var/run/mysqld/mysqld.sock
|
||||||
|
default-character-set = utf8mb4
|
||||||
|
|
||||||
|
# Here is entries for some specific programs
|
||||||
|
# The following values assume you have at least 32M ram
|
||||||
|
|
||||||
|
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
|
||||||
|
[mysqld_safe]
|
||||||
|
socket = /var/run/mysqld/mysqld.sock
|
||||||
|
nice = 0
|
||||||
|
|
||||||
|
[mysqld]
|
||||||
|
character-set-client-handshake = FALSE
|
||||||
|
character-set-server = utf8mb4
|
||||||
|
collation-server = utf8mb4_unicode_ci
|
||||||
|
|
||||||
|
#
|
||||||
|
# * Basic Settings
|
||||||
|
#
|
||||||
|
#user = mysql
|
||||||
|
pid-file = /var/run/mysqld/mysqld.pid
|
||||||
|
socket = /var/run/mysqld/mysqld.sock
|
||||||
|
port = 3306
|
||||||
|
basedir = /usr
|
||||||
|
datadir = /var/lib/mysql
|
||||||
|
tmpdir = /tmp
|
||||||
|
lc_messages_dir = /usr/share/mysql
|
||||||
|
lc_messages = en_US
|
||||||
|
skip-external-locking
|
||||||
|
#
|
||||||
|
# Instead of skip-networking the default is now to listen only on
|
||||||
|
# localhost which is more compatible and is not less secure.
|
||||||
|
#bind-address = 172.17.0.1
|
||||||
|
#
|
||||||
|
# * Fine Tuning
|
||||||
|
#
|
||||||
|
max_connections = 100
|
||||||
|
connect_timeout = 5
|
||||||
|
wait_timeout = 600
|
||||||
|
max_allowed_packet = 16M
|
||||||
|
thread_cache_size = 128
|
||||||
|
sort_buffer_size = 4M
|
||||||
|
bulk_insert_buffer_size = 16M
|
||||||
|
tmp_table_size = 32M
|
||||||
|
max_heap_table_size = 32M
|
||||||
|
#
|
||||||
|
# * MyISAM
|
||||||
|
#
|
||||||
|
# This replaces the startup script and checks MyISAM tables if needed
|
||||||
|
# the first time they are touched. On error, make copy and try a repair.
|
||||||
|
myisam_recover_options = BACKUP
|
||||||
|
key_buffer_size = 128M
|
||||||
|
#open-files-limit = 2000
|
||||||
|
table_open_cache = 400
|
||||||
|
myisam_sort_buffer_size = 512M
|
||||||
|
concurrent_insert = 2
|
||||||
|
read_buffer_size = 2M
|
||||||
|
read_rnd_buffer_size = 1M
|
||||||
|
#
|
||||||
|
# * Query Cache Configuration
|
||||||
|
#
|
||||||
|
# Cache only tiny result sets, so we can fit more in the query cache.
|
||||||
|
query_cache_limit = 128K
|
||||||
|
query_cache_size = 64M
|
||||||
|
# for more write intensive setups, set to DEMAND or OFF
|
||||||
|
#query_cache_type = DEMAND
|
||||||
|
#
|
||||||
|
# * Logging and Replication
|
||||||
|
#
|
||||||
|
# Both location gets rotated by the cronjob.
|
||||||
|
# Be aware that this log type is a performance killer.
|
||||||
|
# As of 5.1 you can enable the log at runtime!
|
||||||
|
#general_log_file = /var/log/mysql/mysql.log
|
||||||
|
#general_log = 1
|
||||||
|
#
|
||||||
|
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
|
||||||
|
#
|
||||||
|
# we do want to know about network errors and such
|
||||||
|
#log_warnings = 2
|
||||||
|
#
|
||||||
|
# Enable the slow query log to see queries with especially long duration
|
||||||
|
#slow_query_log[={0|1}]
|
||||||
|
slow_query_log_file = /var/log/mysql/mariadb-slow.log
|
||||||
|
long_query_time = 10
|
||||||
|
#log_slow_rate_limit = 1000
|
||||||
|
#log_slow_verbosity = query_plan
|
||||||
|
|
||||||
|
#log-queries-not-using-indexes
|
||||||
|
#log_slow_admin_statements
|
||||||
|
#
|
||||||
|
# The following can be used as easy to replay backup logs or for replication.
|
||||||
|
# note: if you are setting up a replication slave, see README.Debian about
|
||||||
|
# other settings you may need to change.
|
||||||
|
#server-id = 1
|
||||||
|
#report_host = master1
|
||||||
|
#auto_increment_increment = 2
|
||||||
|
#auto_increment_offset = 1
|
||||||
|
#log_bin = /var/log/mysql/mariadb-bin
|
||||||
|
#log_bin_index = /var/log/mysql/mariadb-bin.index
|
||||||
|
# not fab for performance, but safer
|
||||||
|
#sync_binlog = 1
|
||||||
|
expire_logs_days = 10
|
||||||
|
max_binlog_size = 100M
|
||||||
|
# slaves
|
||||||
|
#relay_log = /var/log/mysql/relay-bin
|
||||||
|
#relay_log_index = /var/log/mysql/relay-bin.index
|
||||||
|
#relay_log_info_file = /var/log/mysql/relay-bin.info
|
||||||
|
#log_slave_updates
|
||||||
|
#read_only
|
||||||
|
#
|
||||||
|
# If applications support it, this stricter sql_mode prevents some
|
||||||
|
# mistakes like inserting invalid dates etc.
|
||||||
|
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
|
||||||
|
#
|
||||||
|
# * InnoDB
|
||||||
|
#
|
||||||
|
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
|
||||||
|
# Read the manual for more InnoDB related options. There are many!
|
||||||
|
default_storage_engine = InnoDB
|
||||||
|
innodb_buffer_pool_size = 256M
|
||||||
|
innodb_log_buffer_size = 8M
|
||||||
|
innodb_file_per_table = 1
|
||||||
|
innodb_open_files = 400
|
||||||
|
innodb_io_capacity = 400
|
||||||
|
innodb_flush_method = O_DIRECT
|
||||||
|
#
|
||||||
|
# * Security Features
|
||||||
|
#
|
||||||
|
# Read the manual, too, if you want chroot!
|
||||||
|
# chroot = /var/lib/mysql/
|
||||||
|
#
|
||||||
|
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
|
||||||
|
#
|
||||||
|
# ssl-ca=/etc/mysql/cacert.pem
|
||||||
|
# ssl-cert=/etc/mysql/server-cert.pem
|
||||||
|
# ssl-key=/etc/mysql/server-key.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# * Galera-related settings
|
||||||
|
#
|
||||||
|
[galera]
|
||||||
|
# Mandatory settings
|
||||||
|
#wsrep_on=ON
|
||||||
|
#wsrep_provider=
|
||||||
|
#wsrep_cluster_address=
|
||||||
|
#binlog_format=row
|
||||||
|
#default_storage_engine=InnoDB
|
||||||
|
#innodb_autoinc_lock_mode=2
|
||||||
|
#
|
||||||
|
# Allow server to accept connections on all interfaces.
|
||||||
|
#
|
||||||
|
#bind-address=0.0.0.0
|
||||||
|
#
|
||||||
|
# Optional setting
|
||||||
|
#wsrep_slave_threads=1
|
||||||
|
#innodb_flush_log_at_trx_commit=0
|
||||||
|
|
||||||
|
[mysqldump]
|
||||||
|
quick
|
||||||
|
quote-names
|
||||||
|
max_allowed_packet = 16M
|
||||||
|
|
||||||
|
[mysql]
|
||||||
|
default-character-set = utf8mb4
|
||||||
|
no-auto-rehash # faster start of mysql but no tab completion
|
||||||
|
|
||||||
|
[isamchk]
|
||||||
|
key_buffer = 16M
|
||||||
|
|
||||||
|
#
|
||||||
|
# * IMPORTANT: Additional settings that can override those from this file!
|
||||||
|
# The files must end with '.cnf', otherwise they'll be ignored.
|
||||||
|
#
|
||||||
|
!includedir /etc/mysql/conf.d/
|
71
config/nginx/nginx.conf
Normal file
71
config/nginx/nginx.conf
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
events {}
|
||||||
|
|
||||||
|
http {
|
||||||
|
server {
|
||||||
|
server_name localhost;
|
||||||
|
root /var/www/public;
|
||||||
|
index index.php index.html index.htm;
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://node:5173;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-NginX-Proxy true;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
|
proxy_redirect off;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api {
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
# PHP-FPM Configuration Nginx
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri = 404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass php:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param REQUEST_URI $request_uri;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
# server {
|
||||||
|
# server_name localhost;
|
||||||
|
|
||||||
|
# listen 443 ssl;
|
||||||
|
# fastcgi_param HTTPS on;
|
||||||
|
|
||||||
|
# ssl_certificate /etc/ssl/server.pem;
|
||||||
|
# ssl_certificate_key /etc/ssl/server.key;
|
||||||
|
# ssl_protocols TLSv1.3;
|
||||||
|
|
||||||
|
# index index.php index.html;
|
||||||
|
# error_log /var/log/nginx/error.log;
|
||||||
|
# access_log /var/log/nginx/access.log;
|
||||||
|
# root /var/www/html/public;
|
||||||
|
|
||||||
|
# location ~ \.php$ {
|
||||||
|
# try_files $uri =404;
|
||||||
|
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
# fastcgi_pass php:9000;
|
||||||
|
# fastcgi_index index.php;
|
||||||
|
# include fastcgi_params;
|
||||||
|
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
# }
|
||||||
|
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
}
|
||||||
|
}
|
1944
config/php/php.ini
Normal file
1944
config/php/php.ini
Normal file
File diff suppressed because it is too large
Load Diff
1
db/.gitkeep
Normal file
1
db/.gitkeep
Normal file
@ -0,0 +1 @@
|
|||||||
|
# För att behålla katalog
|
63
docker-compose.yml
Normal file
63
docker-compose.yml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
services:
|
||||||
|
|
||||||
|
web:
|
||||||
|
image: nginx:latest
|
||||||
|
container_name: nginx
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
|
- 443:443
|
||||||
|
volumes:
|
||||||
|
- ./www/public:/var/www/public
|
||||||
|
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
|
||||||
|
- ./config/ssl:/etc/ssl
|
||||||
|
- /etc/hostname:/hostname
|
||||||
|
depends_on:
|
||||||
|
- php
|
||||||
|
|
||||||
|
php:
|
||||||
|
build: ./docker/php
|
||||||
|
container_name: php
|
||||||
|
volumes:
|
||||||
|
- ./www:/var/www
|
||||||
|
- ./config/php/php.ini:/usr/local/etc/php/php.ini
|
||||||
|
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:latest
|
||||||
|
container_name: mariadb
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
volumes:
|
||||||
|
- ./db:/var/lib/mysql
|
||||||
|
- ./config/mysql/my.cnf:/etc/mysql/my.cnf
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=12345
|
||||||
|
- MYSQL_DATABASE=db
|
||||||
|
- MYSQL_USER=pma
|
||||||
|
- MYSQL_PASSWORD=12345
|
||||||
|
|
||||||
|
phpmyadmin:
|
||||||
|
image: phpmyadmin/phpmyadmin:latest
|
||||||
|
container_name: pma
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
PMA_HOST: mariadb
|
||||||
|
#PMA_ABSOLUTE_URI: http://localhost/pma/
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
depends_on:
|
||||||
|
- mariadb
|
||||||
|
|
||||||
|
composer:
|
||||||
|
image: composer/composer:latest
|
||||||
|
command: install
|
||||||
|
volumes:
|
||||||
|
- ./composer:/composer
|
||||||
|
|
||||||
|
node:
|
||||||
|
image: node:latest
|
||||||
|
working_dir: /sveltekit
|
||||||
|
command: "npm run dev -- --host 0.0.0.0"
|
||||||
|
volumes:
|
||||||
|
- ./sveltekit:/sveltekit
|
48
docker/php/Dockerfile
Normal file
48
docker/php/Dockerfile
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
FROM php:fpm
|
||||||
|
|
||||||
|
WORKDIR /var/www
|
||||||
|
|
||||||
|
RUN apt-get --allow-releaseinfo-change update && apt-get upgrade -y \
|
||||||
|
&& apt-get install -y \
|
||||||
|
g++ \
|
||||||
|
libbz2-dev \
|
||||||
|
libc-client-dev \
|
||||||
|
libcurl4-gnutls-dev \
|
||||||
|
libedit-dev \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libicu-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libkrb5-dev \
|
||||||
|
libmcrypt-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libsqlite3-dev \
|
||||||
|
libzip-dev \
|
||||||
|
wget \
|
||||||
|
unzip \
|
||||||
|
zlib1g-dev \
|
||||||
|
&& docker-php-ext-install -j$(nproc) \
|
||||||
|
mysqli \
|
||||||
|
pdo_mysql \
|
||||||
|
sockets \
|
||||||
|
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||||
|
&& docker-php-ext-install -j$(nproc) gd \
|
||||||
|
&& docker-php-ext-configure zip \
|
||||||
|
&& docker-php-ext-install zip \
|
||||||
|
&& docker-php-source delete \
|
||||||
|
&& apt-get remove -y g++ wget \
|
||||||
|
&& apt-get autoremove --purge -y && apt-get autoclean -y && apt-get clean -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& rm -rf /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
# Add user
|
||||||
|
RUN groupadd -g 1000 www
|
||||||
|
RUN useradd -u 1000 -ms /bin/bash -g www www
|
||||||
|
|
||||||
|
# Copy existing application directory contents
|
||||||
|
COPY ./ /var/www
|
||||||
|
|
||||||
|
# Copy existing application directory permissions
|
||||||
|
COPY --chown=www:www ./ /var/www
|
||||||
|
|
||||||
|
# Change current user to www
|
||||||
|
USER www
|
1
sveltekit/.npmrc
Normal file
1
sveltekit/.npmrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
engine-strict=true
|
38
sveltekit/README.md
Normal file
38
sveltekit/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# create-svelte
|
||||||
|
|
||||||
|
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||||
|
|
||||||
|
## Creating a project
|
||||||
|
|
||||||
|
If you're seeing this, you've probably already done this step. Congrats!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# create a new project in the current directory
|
||||||
|
npm create svelte@latest
|
||||||
|
|
||||||
|
# create a new project in my-app
|
||||||
|
npm create svelte@latest my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# or start the server and open the app in a new browser tab
|
||||||
|
npm run dev -- --open
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To create a production version of your app:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
You can preview the production build with `npm run preview`.
|
||||||
|
|
||||||
|
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
2863
sveltekit/package-lock.json
generated
Normal file
2863
sveltekit/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
sveltekit/package.json
Normal file
17
sveltekit/package.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "sveltekit",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite dev",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/adapter-auto": "next",
|
||||||
|
"@sveltejs/kit": "next",
|
||||||
|
"svelte": "^3.44.0",
|
||||||
|
"vite": "^3.1.0"
|
||||||
|
},
|
||||||
|
"type": "module"
|
||||||
|
}
|
12
sveltekit/src/app.html
Normal file
12
sveltekit/src/app.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
%sveltekit.head%
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>%sveltekit.body%</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
34
sveltekit/src/routes/+page.svelte
Normal file
34
sveltekit/src/routes/+page.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
let loadData = { done: false };
|
||||||
|
let posts;
|
||||||
|
|
||||||
|
onMount(getPosts);
|
||||||
|
|
||||||
|
async function getPosts() {
|
||||||
|
loadData.done = false;
|
||||||
|
|
||||||
|
let url = "http://localhost/api/post.php";
|
||||||
|
|
||||||
|
let response = await fetch(url);
|
||||||
|
posts = await response.json();
|
||||||
|
|
||||||
|
loadData.done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Welcome to your library project</h1>
|
||||||
|
<p>
|
||||||
|
Create your package using @sveltejs/package and preview/showcase your work
|
||||||
|
with SvelteKit
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#if loadData.done}
|
||||||
|
<p>{posts.name}, {posts.age}</p>
|
||||||
|
{:else}
|
||||||
|
<p>väntar</p>
|
||||||
|
{/if}
|
34
sveltekit/src/routes/array/+page.svelte
Normal file
34
sveltekit/src/routes/array/+page.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script>
|
||||||
|
let promise = getPosts();
|
||||||
|
|
||||||
|
async function getPosts() {
|
||||||
|
|
||||||
|
const url = "http://localhost/api/posts.php"; // OBS! Annat API
|
||||||
|
|
||||||
|
const response = await fetch(url);
|
||||||
|
const posts = await response.json();
|
||||||
|
|
||||||
|
if(response.ok){
|
||||||
|
return posts;
|
||||||
|
}else{
|
||||||
|
throw new Error("Kunde inte hämte från servern.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Welcome to your library project</h1>
|
||||||
|
<p>
|
||||||
|
Create your package using @sveltejs/package and preview/showcase your work
|
||||||
|
with SvelteKit
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#await promise}
|
||||||
|
<p>Laddar...</p>
|
||||||
|
{:then posts}
|
||||||
|
{#each posts as post}
|
||||||
|
<p>{post.name}, {post.age}</p>
|
||||||
|
{/each}
|
||||||
|
{/await}
|
32
sveltekit/src/routes/await/+page.svelte
Normal file
32
sveltekit/src/routes/await/+page.svelte
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
let promise = getPosts();
|
||||||
|
|
||||||
|
async function getPosts() {
|
||||||
|
|
||||||
|
const url = "http://localhost/api/post.php";
|
||||||
|
|
||||||
|
const response = await fetch(url);
|
||||||
|
const post = await response.json();
|
||||||
|
|
||||||
|
if(response.ok){
|
||||||
|
return post;
|
||||||
|
}else{
|
||||||
|
throw new Error("Kunde inte hämte från servern.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Welcome to your library project</h1>
|
||||||
|
<p>
|
||||||
|
Create your package using @sveltejs/package and preview/showcase your work
|
||||||
|
with SvelteKit
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#await promise}
|
||||||
|
<p>Laddar...</p>
|
||||||
|
{:then post}
|
||||||
|
<p>{post.name}, {post.age}</p>
|
||||||
|
{/await}
|
BIN
sveltekit/static/favicon.png
Normal file
BIN
sveltekit/static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
10
sveltekit/svelte.config.js
Normal file
10
sveltekit/svelte.config.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import adapter from '@sveltejs/adapter-auto';
|
||||||
|
|
||||||
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
const config = {
|
||||||
|
kit: {
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
7
sveltekit/vite.config.js
Normal file
7
sveltekit/vite.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
plugins: [sveltekit()]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
8
www/public/api/post.php
Normal file
8
www/public/api/post.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
$response["name"] = "Henrik";
|
||||||
|
$response["age"] = 11;
|
||||||
|
|
||||||
|
header('Access-Control-Allow-Origin: *'); // http://localhost
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
echo json_encode($response);
|
17
www/public/api/posts.php
Normal file
17
www/public/api/posts.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
$user["name"] = "Henrik";
|
||||||
|
$user["age"] = 11;
|
||||||
|
$response[] = $user;
|
||||||
|
|
||||||
|
$user["name"] = "Eva";
|
||||||
|
$user["age"] = 14;
|
||||||
|
$response[] = $user;
|
||||||
|
|
||||||
|
$user["name"] = "Lisa";
|
||||||
|
$user["age"] = 15;
|
||||||
|
$response[] = $user;
|
||||||
|
|
||||||
|
header('Access-Control-Allow-Origin: *'); // http://localhost
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
echo json_encode($response);
|
55
www/public/index.php
Normal file
55
www/public/index.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="sv">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Error Sökväg</title>
|
||||||
|
<style>
|
||||||
|
html{
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 800px){
|
||||||
|
html{
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 400px){
|
||||||
|
html{
|
||||||
|
font-size: 50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div{
|
||||||
|
position: relative;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
width: fit-contet;
|
||||||
|
font-family: Roboto, sans-serif;
|
||||||
|
font-size: 10rem;
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 span{
|
||||||
|
font-size: 6.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2{
|
||||||
|
font-family: Roboto, sans-serif;
|
||||||
|
font-size: 4rem;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1>404 <span>Error</span></h1>
|
||||||
|
<h2>Felaktig sökväg</h2>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user