Skip to content

Commit

Permalink
Merge branch 'geoffrich:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
FlippingBinary authored Oct 5, 2022
2 parents d1cc7e8 + 90e19bd commit 2d3e947
Show file tree
Hide file tree
Showing 7 changed files with 2,210 additions and 302 deletions.
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contribution Guidelines

## How to contribute

- Open a [GitHub Issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues) for a discussion of your idea before working on it
- Fork this repo, develop your solution and submit a PR

## What to contribute

See the [GitHub Issues](https://github.com/geoffrich/svelte-adapter-azure-swa/issues) list for any open Issue.

General improvements to any aspect of this adapter are welcome, just ensure major work is preceeded by a conversation in a [GitHub Issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues).

## Package scripts

- `npm run format`: format the code using Prettier
- `npm run format`: check that the code is correctly formated
- `npm run test`: run the unit tests using [Vitest](https://vitest.dev/)
- `npm run test:coverage`: check test coverage

_This was based on the contribution guidelines in [svelte-adapter-firebase](https://github.com/jthegedus/svelte-adapter-firebase/blob/main/CONTRIBUTING.md)_
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default {

An object containing additional [esbuild options](https://esbuild.github.io/api/#build-api). Currently only supports [external](https://esbuild.github.io/api/#external). If you require additional options to be exposed, plese [open an issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues).


```js
import azure from 'svelte-adapter-azure-swa';

Expand Down
74 changes: 43 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,14 @@ export default function ({
name: 'adapter-azure-swa',

async adapt(builder) {
validateCustomConfig(customStaticWebAppConfig);

if (!customStaticWebAppConfig.routes) {
customStaticWebAppConfig.routes = [];
}

/** @type {import('./types/swa').StaticWebAppConfig} */
const swaConfig = {
...customStaticWebAppConfig,
routes: [
...customStaticWebAppConfig.routes,
{
route: '*',
methods: ['POST', 'PUT', 'DELETE'],
rewrite: ssrFunctionRoute
},
{
route: `/${builder.config.kit.appDir}/immutable/*`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
],
navigationFallback: {
rewrite: ssrFunctionRoute
},
platform: {
apiRuntime: 'node:16'
}
};

if (!existsSync(join('api', 'package.json'))) {
throw new Error(
'You need to create a package.json in your `api` directory. See the adapter README for details.'
);
}

const swaConfig = generateConfig(customStaticWebAppConfig, builder.config.kit.appDir);

const tmp = builder.getBuildDirectory('azure-tmp');
const publish = 'build';
const staticDir = join(publish, 'static');
Expand Down Expand Up @@ -113,6 +84,7 @@ export default function ({
bundle: true,
platform: 'node',
target: 'node16',
sourcemap: 'linked',
external: esbuildOptions.external
};

Expand Down Expand Up @@ -143,3 +115,43 @@ export default function ({
}
};
}

/**
* @param {import('./types/swa').CustomStaticWebAppConfig} customStaticWebAppConfig
* @param {string} appDir
* @returns {import('./types/swa').StaticWebAppConfig}
*/
export function generateConfig(customStaticWebAppConfig, appDir) {
validateCustomConfig(customStaticWebAppConfig);

if (!customStaticWebAppConfig.routes) {
customStaticWebAppConfig.routes = [];
}

/** @type {import('./types/swa').StaticWebAppConfig} */
const swaConfig = {
...customStaticWebAppConfig,
routes: [
...customStaticWebAppConfig.routes,
{
route: '*',
methods: ['POST', 'PUT', 'DELETE'],
rewrite: ssrFunctionRoute
},
{
route: `/${appDir}/immutable/*`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
],
navigationFallback: {
rewrite: ssrFunctionRoute
},
platform: {
apiRuntime: 'node:16'
}
};

return swaConfig;
}
Loading

0 comments on commit 2d3e947

Please sign in to comment.