Skip to content

Commit

Permalink
fixed all the bugs when running the backend on wasmer
Browse files Browse the repository at this point in the history
  • Loading branch information
pwlin committed Aug 8, 2024
1 parent e7d5e7b commit fa0bb3d
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 38 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Continuous Integration

on:
pull_request:
push:
branches:
- main

env:
GITHUB_TOKEN: ${{ github.token }}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build_and_deploy:
name: Build and Deploy PHP site to Wasmer Edge
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Wasmer
uses: wasmerio/setup-wasmer@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
# tools: composer
# - name: Get composer cache directory
# id: composer-cache
# run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
# - name: Cache dependencies
# uses: actions/cache@v4
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: ${{ runner.os }}-composer-
# - name: Install dependencies
# run: composer install --prefer-dist
- name: Deploy app to Wasmer Edge
run: wasmer deploy --token=${{ secrets.WASMER_CIUSER_PROD_TOKEN }} --non-interactive --no-wait --no-persist-id
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ client/feeds.json
client/Neo.toml
package-lock.json
server/cache
app.yaml
2 changes: 1 addition & 1 deletion client/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main_color": "red",
"second_color": "black",
"api_key": "dev-api-key",
"api_url": "http://127.0.0.1:8080/index.php",
"api_url": "http://127.0.0.1:8081/index.php",
"favicons_enabled": false,
"redirlinks_enabled": false
}
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'self';
script-src 'self';
style-src 'self';
img-src 'self' data: http://localhost:* http://127.0.0.1:*;
img-src 'self' data: http://localhost:* http://127.0.0.1:* https:;
connect-src 'self' wss: ws: http://localhost:* http://127.0.0.1:* https:;
font-src 'self' data:;" />
</head>
Expand Down
2 changes: 1 addition & 1 deletion client/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Config {
constructor() {
this.config = null;
this.defaultConfig = {
'xml2json_endpoint': '/xml2json?url=__URL__&_t=__TS__',
'xml2json_endpoint': '/xml2json?url=__URL__&_t=__TS__&api_key=__API_KEY__',
'favicon_endpoint': '/favicon?url=__URL__&api_key=__API_KEY__',
'revredir_endpoint': '/revredir?url=__URL__&api_key=__API_KEY__'
};
Expand Down
7 changes: 3 additions & 4 deletions client/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ class Model {
* @returns {Promise<Array>} A promise that resolves to the normalized feed data.
*/
async fetchFeed(feed) {
const apiKey = config.get('api_key');
const serviceUrl = `${config.get('api_url')}${config.get('xml2json_endpoint').replace('__URL__', encodeURIComponent(feed.feedUrl)).replace('__TS__', utils.ts())}`;
const response = await fetch(serviceUrl, {
const serviceUrl = `${config.get('api_url')}${config.get('xml2json_endpoint').replace('__URL__', encodeURIComponent(feed.feedUrl)).replace('__TS__', utils.ts()).replace('__API_KEY__', config.get('api_key'))}`;
const response = await fetch(serviceUrl/*, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
}*/);
const content = await response.json();

// Normalize the general structure of the feed entries
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dev-client": "node node_modules/vite/bin/vite.js --clearScreen false",
"build-client": "node node_modules/vite/bin/vite.js build",
"preview-client": "node node_modules/vite/bin/vite.js preview",
"dev-server": "php -S localhost:8080 -t ./server"
"dev-server": "php -S localhost:8081 -t ./server"
},
"devDependencies": {
"vite": "^5.3.4",
Expand Down
5 changes: 5 additions & 0 deletions server/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);

// Set a flag indicating that the salad API file has been included
$salad_api_file_included = true;

Expand Down
59 changes: 29 additions & 30 deletions server/salad-api.php

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions wasmer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[dependencies]
"php/php" = "=8.3.4"

[fs]
"/server" = "server"

[[command]]
name = "run"
module = "php/php:php"
runner = "wasi"
[command.annotations.wasi]
main-args = ["-t", "/server", "-S", "localhost:8080"]

0 comments on commit fa0bb3d

Please sign in to comment.